Skip to content

Instantly share code, notes, and snippets.

@smoya
Last active May 8, 2017 16:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save smoya/c49144f01470ebb403df to your computer and use it in GitHub Desktop.
Save smoya/c49144f01470ebb403df to your computer and use it in GitHub Desktop.
Get php trace -on segmentation fault- using xdebug
  • Enable the tracer on your xdebug.ini file (see the xdebug.ini file).
  • If you are gonna trace an http request, make sure your xdebug.trace_output_dir is writable by the webserver user (www-data).
  • Execute your script or your request. You can use produce_segmentation.php to test.
  • See the trace file(s) on your xdebug.trace_output_dir.
<?php
class foo {
function fail()
{
// This preg_match will produce segmentation fault
// .ru because Russian people love Adidas jackets like I do. http://weirdrussia.com/2015/01/04/why-is-adidas-so-popular-among-russians
preg_match("/http:\/\/(.)+\.ru/i", str_repeat("http://google.ru", 2000));
}
}
class bar {
function doit()
{
$destroyer = new foo();
$destroyer->fail();
}
}
$obj = new bar();
$obj->doit();
; Example: /etc/php5/mods-available/xdebug.ini
[xdebug]
zend_extension=/usr/lib/php5/20121212/xdebug.so ; Path to your extension
xdebug.auto_trace=1
xdebug.trace_output_dir=/tmp/segmentation/ ; Or whatever path you want to use
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment