[PHP-DEV] Bug #854 Updated: include() problem From: Bug Database (php-dev <email protected>)
Date: 10/17/98

ID: 854
Updated by: zeev
Reported By: matt <email protected>
Status: Closed
Bug Type: Reproduceable crash
Assigned To:
Comments:

Ok, at last, I'm at your help :)

I've reproduced the problem on your box. I also fixed it.
Basically, at a certain point, the script runs out of memory,
or actually, it can't find a sufficiently big memory block.

Since PHP doesn't handle out of memory errors (we never got
around to it) - the script crashed.

Using include() within a loop is *VERY* bad practice, since
it 'leaks' memory. That is, memory is allocated separately
for each include file, and is NEVER freed until the end of
the script execution. In your case, you should really consider
one of the following alternatives:

1. Define a function that does what the include file does,
and call that function instead of repeatedly including
the include file.

2. Use require() instead. require() only parses the include
file once, and allcoates memory for it once.

As far as proper coding is concerned, (1) is much much better.

I'll make sure we handle out of memory errors nicely in
3.0.6, but that won't solve your problem - since all I'm
planning to do is exit(), instead of the current situation
which may crash under some circumstances.

Full Bug description available at: http://ca.php.net/bugs.php3?id=854

--
PHP Development Mailing List   http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe <email protected>
For help: php-dev-help <email protected>