[Toolserver-l] protip: i/o and infinite loops in php
River Tarnell
river at wikimedia.org
Wed Jan 23 07:56:59 UTC 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
never do this:
do {
$x = file_get_contents("http://www.example.com/");
} while ($x === false);
or this:
while (!feof($f)) {
$x .= fgets($f);
}
why not: because if the i/o fails, your script will run forever, using
100% cpu, doing nothing.
instead, add error checking, and exit if there's a problem:
if (($x = file_get_contents("http://www.example.com") === false) {
echo "shit happened\n";
exit;
}
please make sure none of your scripts have this problem, because they
cause issues for all users on the toolserver.
- river.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
iD8DBQFHlvNLIXd7fCuc5vIRAjndAJ9Z+SFfe412VLIymbCZLYnDvqHXbQCeMUjo
FQOj5I2OpULhcqsVBJ0706M=
=xzww
-----END PGP SIGNATURE-----
More information about the Toolserver-l
mailing list