Segmentation Fault when running PHP Cli

user622378 picture user622378 · Jul 6, 2011 · Viewed 9.7k times · Source

When I type this in shell (Linux):

php index.php

Sometime PHP script terminate and I get an error saying:

Segmentation Fault

Sometime it work fine and sometime I get an error

In the php script it include PDO (mysql), Curl, some loop and "Simple HTML Dom" library

PHP Version:

username [~/www/]# php -v
PHP 5.2.9 (cli) (built: Oct  9 2010 02:01:46)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    with the ionCube PHP Loader v3.3.20, Copyright (c) 2002-2010, by ionCube Ltd., and
    with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technolog

How to fix this problem? I had no problem when I tested on Windows 7 (PHP 5.3.0).

Answer

Mathieu Rodic picture Mathieu Rodic · Jul 20, 2011

It is about a memory access violation. In your case, this error may be due to (non-exhaustive list):

  1. a stack overflow (often happens when the recursion level for a given function is too high)

  2. too much data to be put in variables (e.g., you try to put the whole content of a huge file in a variable)

To know what causes trouble in your script, try commenting bigger and bigger parts to see which one is at the origin of the bug.