How can PHP cause memory leaks, buffer overflows, stack overflows and any other errors of such kind? Can PHP even cause such errors?
<?php require __FILE__; ?>
This should cause a stack overflow.
There's an article out there you might want to read: Top 10 ways to crash PHP.
PHP is a interpreted language, so all php scripts are protected from memory leaks, buffer overflow and stack overflow.
How ever you will encounter problems as such:
Integer overflow, if you assign a number too large it will overflow, and no exception will occur.
Out of memory, using more memory than memory size configured in your php.ini
You can either do the stuff that would cause overflows in any language (like recursively calling the current function, mindlessly eating memory, etc.) or rely on the good old PHP interpreter to do that job. Just have a look at how many memory leaks were fixed in PHP5 (My favorite: In 5.2.6 they fixed bug #44069: 'Huge memory usage with concatenation using .
instead of .=
').
All in all PHP is ok (at most) if you just want to serve a single http request. But you can't really do sophisticated stuff with it (I once tried implementing a Peer2Peer client, the server died of memory shortage after just 10 minutes - could be a bug on my behalf of course, but I had spent several days finding leaks in my own code - to no avail).