Jun 21

Message:

PHP Warning: Cannot modify header information - headers already sent by (output started at /home/w.php:189) in /home/start.php on line 64

Error type: warning

Symptoms:

You try to send a header value from PHP (for example a redirect) and it fails with this warning.

Sample Code:

<?php
echo ‘Redirecting: ‘;
header(‘Location: /’);
exit;
?>

Cause:

You must send headers before you output anything on that page. This means you can’t use echo, printf or any other output function before all headers are sent.

Fix:

Check where you used the header() function and remove any output instructions before that.

Please note that blank spaces before <?php are also considered part of the output and will give you lots of trouble. This also applies to files you include (for example configuration files), so make sure you don’t leave extra spaces/empty lines).

Another method to get rid of this problem is to use output buffering.

Jun 21

Message:

PHP Warning:fsockopen(): unable to connect to rpc.technorati.com:80 (Connection timed out) in /home/public_html/pinger.php on line 66

Error type: warning

Symptoms:

You try to open a socket to a remote location, but your connection is timed out (you don’t receive any response).

Sample Code:

<?php
$fs = fsockopen($ping_host, $ping_port, $errno, $errstr);

if (is_resource($fs))
{
stream_set_write_buffer($fs,0);
fwrite($fs, $http_request);
while (!feof($fs))
{
$response .= fgets($fs, 2048);
}
fclose($fs);
}
?>

Cause:

The host you are trying to connect to is either down or takes too long to respond (or from other reasons, you just can’t get a response).

Fix:

Get a beer, watch a movie, play a game … really, there’s not much you can do usually. Wait a few minutes and try again. If you still get the same response check if there is any problem with your server (for example DNS problems), eventually contact your hosting provider.

Jun 21

Message:

PHP Warning: Variable passed to each() is not an array or object in /home/functions.php on line 23

Error type: warning

Symptoms:

You try to use each, but instead of going through the loop, you just receive a warning.

Sample Code:

<?php
while (list($key, $val) = each ($myvar))
{
echo $key.’ ‘;
}
?>

Cause:

You try to use the each() function with a null, integer or string variable (or generally not an array or object). This might be caused by an uninitialized variable you try to use with each();

Fix:

Make sure the variable you try to pass exists and is not null first. You should also make sure you didn’t misspell the variable name (if you try to use a variable that has not been initialized you get the same warning).

You should try to use function is_array($array) to make sure the variable passed is indeed an array.

Jun 21

Message:

PHP Warning: reset(): Passed variable is not an array or object in /home/cron.php on line 43

Error type: warning

Symptoms:

You get a reset() warning although the code seems to work fine.

Sample Code:

<?php
$string = “This is a string.”;
reset($string);
?>

Cause:

You try to use the reset() function with a null, an integer or a string (these are most common), when you should only use it with an array or object. Usually this is caused by accidental type casting or misspelling of variable names.

Fix:

Make sure the variable you try to reset exists and is not null first. You should also make sure you didn’t misspell the variable name (if you try to reset a variable that has not been initialized you get the same warning).

Jun 21

Message:

Fatal error: Allowed memory size of 867300 bytes exhausted (tried to allocate 1280200 bytes) in /home/public_html/index.php on line 135

Error type: fatal error

Symptoms:

Page parsing fails and you receive the message in the output. Usually associated with GD (image manipulation) functions or when you deal with large arrays.

Cause:

You do not have enough memory (RAM) available to run that script. This doesn’t happen too often, but you can receive this error when working with large images or with other memory consuming functions (or just large arrays).

Fix:

Set the memory limit to a larger value using:

ini_set("memory_limit","32M");

In that example it is set to 32MB for that particular script. Be careful how much you allow PHP to use because it can slow your entire server down (and it can even cause it to crash!)

You can also change the global value for memory limit from php.ini (if you have access to it):

memory_limit = 32M

Another method is through .htaccess (again, if you have access to that). Please note that this changes the memory limit for all scripts unless you manually specify otherwise.

php_value memory_limit 32M

Jun 21

Message:

Fatal error: Call to undefined function myfunction() in /www/myproject/index.php on line 1345

Error type: fatal error

Symptoms:

Page parsing fails and you receive that message in the output. If display_errors is set to Off in php.ini you will need to check error logs for the message.

Sample Code:

<?php
$id = $_GET[‘id’];
myfunction($id);
?>

Cause:

You are attempting to call a function which does not exist. If you are trying to call a function that you have defined yourself, then make sure that the script has access to it, or if it is a standard PHP function, check  your spelling  and make sure you have the necessary extensions.

Fix:

Check the file with error indicated in the error output and make sure you didn’t misspell the function name.

If that function is defined in a different file make sure that you include (using include/require) before you call it.

Jun 21
Welcome to PHPedia
icon1 admin | icon2 Uncategorized | icon4 06 21st, 2008| icon31 Comment »

Hello there!

If you’re wondering what this website is about, here’s your answer: a website where you can find the solution for any PHP problem you might encounter: PHP syntax errors, PHP unexpected results or other stuff that might hold you back from developing that awesome script you were working on.

Want to give me a hand?

If you wish to contribute to this website, just register yourself a new account and write something to help humanity (ok, maybe just a few people, but still, that’s something!)