Skip to main content

Posts

Showing posts with the label segmentation-fault

PHP weird Seg-faults on mysqli_stmt_bind_result

When migrating a PHP script from PHP 5.2 to PHP 5.3, I've stumbled to the following problem: The general purpose of the script is data mining. I have a procedure inside that adds data to the MySQL server. Since it is really repetitive, I've rewritten it (a while ago) to use MySQLi, in particular prepared statements, since there are a total of 3 possible queries to perform. Anyway, now, on the PHP 5.3 server, the script is crashing on the following line:

Why does an infinitely recursive function in PHP cause a segfault?

A hypothetical question for you all to chew on... I recently answered another question on SO where a PHP script was segfaulting, and it reminded me of something I have always wondered, so let's see if anyone can shed any light on it. Consider the following: <?php function segfault ($i = 1) { echo "$i\n"; segfault($i + 1); } segfault(); ?> Obviously, this (useless) function loops infinitely. And eventually, will run out of memory because each call to the function executes before the previous one has finished. Sort of like a fork bomb without the forking. But... eventually, on POSIX platforms, the script will die with SIGSEGV (it also dies on Windows, but more gracefully - so far as my extremely limited low-level debugging skills can tell). The number of loops varies depending on the system configuration (memory allocated to PHP, 32bit/64bit, etc etc) and the OS but my real question is - why does it happen with a segfault? Is this simply how