Howdy all!
Quite a long title, but let me explain this issue I have been figthing with for a while now. There's a piece of PHP code that causes PHP processs to die with a segmentation fault, however this same code runs fine in other platforms / situations, so I don't think that the problem is a PHP bug, but rather a problem on how PHP is compiled on FreeBSD.
The code in question is in a pastie, as takes 8kb: PHP test code.
To test this code, I use [cmd=]# php test.php[/cmd]. Expected output is:
Faulty output is:
I'm using a clean base intall of FreeBSD 8.3-RELEASE amd64, with PACKAGESITE set to ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-8-stable/Latest/ for the tests.
Running the test with:
I know that GCC 4.4 is deprecated, but some time ago I also tried with 4.6 and 4.7, and those were causing the same issue. I will re-run the tests with these versions again.
Also note that modifying the string in the text code by removing some of the "x", makes the code work in the otherwise faulty PHP versions.
The questions:
Thanks for any suggestions.
Quite a long title, but let me explain this issue I have been figthing with for a while now. There's a piece of PHP code that causes PHP processs to die with a segmentation fault, however this same code runs fine in other platforms / situations, so I don't think that the problem is a PHP bug, but rather a problem on how PHP is compiled on FreeBSD.
The code in question is in a pastie, as takes 8kb: PHP test code.
To test this code, I use [cmd=]# php test.php[/cmd]. Expected output is:
Code:
Before preg_replace_callback: 7996
After preg_replace_callback: 17
Faulty output is:
Code:
Before preg_replace_callback: 7996
Segmentation fault (core dumped)
I'm using a clean base intall of FreeBSD 8.3-RELEASE amd64, with PACKAGESITE set to ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-8-stable/Latest/ for the tests.
Running the test with:
- PHP 5.3.17 pre-compiled package: works OK.
- PHP 5.4.7 pre-compiled package: Segmentation Fault.
- PHP 5.3.23 built from ports with default GCC 4.2.2: Segmentation Fault.
- PHP 5.3.23 built from ports with GCC 4.4.7: works OK.
I know that GCC 4.4 is deprecated, but some time ago I also tried with 4.6 and 4.7, and those were causing the same issue. I will re-run the tests with these versions again.
Also note that modifying the string in the text code by removing some of the "x", makes the code work in the otherwise faulty PHP versions.
The questions:
- As the test code runs fine or segfaults in PHP 5.3 depending on how it is compiled, what is the ideal way to compile PHP from the ports?
- PHP 5.4 does a segmentation fault even with the precompiled package, however the code runs fine using the PHP 5.4 binaries for Windows. Any suggestions on where to go from here? I don't think it's a PHP bug, but maybe it's platform dependent. Should I report it somewhere specific?
- If any of you guys have a FreBSD box running PHP 5.4, can you give a try to the code and let me know if it works without segfaulting?
Thanks for any suggestions.