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

后端 未结 3 1202
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 09:44

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 ha

3条回答
  •  春和景丽
    2020-12-03 10:23

    I could be totally wrong about this since my testing was fairly brief. It seems that Php will only seg fault if it runs out of memory (and presumably tries to access an invalid address). If the memory limit is set and low enough, you will get an out of memory error beforehand. Otherwise, the code seg faults and is handled by the OS.

    Can't say whether this is a bug or not, but the script should probably not be allowed to get out of control like this.

    See the script below. Behavior is practically identical regardless of options. Without a memory limit, it also slows my computer down severely before it's killed.

    = 0; $x++) {
             print_memory_usage();
             $a[] = $x;
          }
       break;
       default:
          die("Usage: " . __FILE__ . " <-i-or--r> [-l]\n");
       break;
    }
    ?>
    

提交回复
热议问题