English 中文(简体)
PHP segmentation fault caused by php while loop
原标题:

I discovered a way to make php segfault, and I m a bit curious about what s happening. Maybe someone can explain this for me?

joern@xps:..com/trunk5/tools/nestedset> cat > while.php
<?php
while(1){
        die( dd );
}
?>
^C
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php   
ddzsh: segmentation fault  php -f while.php
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php
dd%                                                                                                                                                                                 
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php
dd%                                                                                                                                                                                 
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php
ddzsh: segmentation fault  php -f while.php
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php
ddzsh: segmentation fault  php -f while.php
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php
dd%                                                                                                                                                                                 
0 joern@xps:..com/trunk5/tools/nestedset> php -f while.php
dd%    

As you can see, it doesn t happen every time. Php caching?

php5 5.2.10.dfsg.1-2ubuntu6.1
最佳回答

Wikipedia: Segmentation Fault

A little bit of research indicates that some PHP extensions may not play nice, or may not play nice with each other. It can also depend on the server, or the server configuration.

If you are using both XDebug and Zend Debugger loaded at the same time it can cause this.

At first I thought possibly the while loop used with a die() statement might be part of the cause.. I am curious to know if this also causes a segmentation error:

while (!$fault) { 
  $fault=check_fault_function();
  }
if ($fault) { die( dd ); }

If not it may be just how you are using while and die together. As you know while(1) {} is an infinite loop... (your server may not know how to allocate memory for infinite routines) so unless you are trying to cause crashes this is normally bad practice.

问题回答

This appears to be related to a known bug in the PHP source. It s been fixed in the PHP trunk, and it looks like it was rolled out some time around the 5.2.11 release. See here and here for details.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签