I have a PHP website was build by using Codeigniter framework. I always got the following error message form Apache log:
PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 8192 bytes) in /usr/local/apache2/htdocs/mywebsite/application/helpers/my_helper.php on line 150
About my_helper.php on line 150 is the following:
function objectToArray( $object ){
if( !is_object( $object ) && !is_array( $object ) )
{
return $object;
}
if( is_object( $object ) )
{
$object = get_object_vars( $object ); # <<<<<<< Line 150
}
return array_map( 'objectToArray', $object );
}
The function of "objectToArray" is using to process XPATH result object form XML file(I use simplexml_load_file to load the XML file).
# The example to pass XML object by following: #
$xmlObject = simplexml_load_file(PATH_TO_XML_FILE, 'SimpleXMLElement', LIBXML_NOCDATA);
$data = $xmlObject->xpath(MY_XPATH);
$ary = objectToArray($data);
Also I tried to set the memory_limit value to unlimit(ini_set('memory_limit',-1)), but it still have the error.
Is there have any tuning about hardware or programing to prevent the problem? Thanks!