Posts mit dem Label PHP werden angezeigt. Alle Posts anzeigen
Posts mit dem Label PHP werden angezeigt. Alle Posts anzeigen

Sonntag, 2. Februar 2014

PHP Segmentation fault

This is the worst case for every php developer when hacking some code - your script runs not as expected and you get a simple message saying "Segmentation fault".

Here are the steps you can do, to track down this error.


Some simple tips to start


- Use a debugger like ZendDebugger or XDebug to find the line of code causing the error.

- Disable PHP's internal garbage collector. The garbage collector is known to often cause segmentation faults. If disabling will help you are probably found an internal reference counting bug in the garbage collector
ini_set('zend.enable_gc', 0);
- Look for recursion in your code. PHP throws a segmentation fault if you have a infinite recursion in your code

- If you have apc installed sometimes it helps to empty the cache or disable the cache

Use strace

If php runs on Linux or Mac OS you can use strace/dtruss to hook into the process and see what's happening. Strace can be installed on Debian by running

apt-get install strace

Run phpunit with strace

$ strace phpunit

Attach strace to a already running process

$ sudo strace -s 256 -p <PID>

Run any php script with strace

$ strace php index.php

Attach strace to a running cgi process

$ ps axf | grep php5-cgi # lists all running processes
#If more than one process is found you can use the tool php-strace (see below) to trace all processes at the same time. If only one process is found you can use the following command to trace:
$ sudo strace -s 256 -p <PID>
#For debugging purposes I recommend to limit the cgi processes running to one, so you can be sure to hook into the right process which is serving your browser.
# The number of running cgi processes can be edited by editing the file /etc/php5/fpm/pool.d/www.conf .

Gdb

Also you can try to run the script inside of gdb. On Debian gdb can be installed using the command "apt-get install gdb"

gdb --args php /usr/bin/phpunit
#inside gdb enter:
set env MALLOC_CHECK_=3
#then enter:
r

php-strace

I wrote a tool for easy monitoring running cgi proccesses on a server or a developer box.

php-strace helps to track down segfaults in running php processes. It starts a new strace instance for every running php5-cgi or php-fpm process to monitor whether a segfault happened.


php-strace

To get started, visit my github page. https://github.com/markus-perl/php-strace

Update

php-strace V0.3 available:
https://dl.dropboxusercontent.com/u/32252351/github/php-strace-0.3.tar.gz


Sonntag, 30. Mai 2010

IPC 2010 Berlin Wifi fix

1. Download: http://launchpadlibrarian.net/33927923/rtl8192se_linux_2.6.0010.1012.2009.tar.gz

2. Extract archive

3. open a shell and change to root (pw intellibook): $sudo su

4. $make

5. $make install

6. $modprobe r8192se_pci

7. That's it!

Samstag, 1. Mai 2010

HowTo install ZendDebugger for PHP 5.3.1 and 5.3.2 on Linux

This article is deprecated. Please refer to HowTo install ZendDebugger for PHP 5.4 or PHP 5.5 on Debian


If you try to download a current build of the ZendDebugger from Zend.com you probably get the following error:
Zend Debugger requires Zend Engine API version 220060519.The Zend
Engine API version 220090626 which is installed, is newer.Contact
Zend Technologies at http://www.zend.com/ for a  later version of Zend Debugger.
This happens because there is no Build for PHP 5.3.2 or 5.3.1 available.
But if you take a look at the Zend Server release notes you will see, that Zend Server is shipped with PHP 5.3.2 and an enabled debugging runtime environment.

So if you use debian or ubuntu you can simply add the Zend-Server deb repository to your apt/sources.lit

  1. copy the following line into /etc/apt/sources.list
    deb http://repos.zend.com/zend-server/deb server non-free
  2. update your local package list:
    $: sudo aptitude update 
  3. install the debugger
    $: sudo aptitude install php-5.3-debugger-zend-server 
  4. The ZendDebugger is now located under /usr/local/zend/lib/debugger/php-5.3.x/ZendDebugger.so
  5. Now create a new ini file under /etc/php5/conf.d/ and add the following lines:
    zend_extension=/usr/lib/php5/20060613/ZendDebugger.so
    zend_debugger.allow_hosts=127.0.0.1
    zend_debugger.expose_remotely=always
  6. call the following command in your console to see if everything works:
    $: php -i | grep "Zend Debug"
    
    Output: "with Zend Debugger v5.3, Copyright (c) 1999-2010, by Zend Technologies"