Areso Posted November 19, 2017 Share Posted November 19, 2017 PHP Version 5.5.9 Apache 2 100 iterations works flawlessly, but if I tried more (for example, 200), I got ERROR 500. I check memory consumption, it doesn't look so bad, about 600KB . So, IDK why it crashes to error, when I increase my iterator. I tried some tricks, but had no luck with them. IDK why, but if the script crashed to 500 error, it doesn't show me even first echos... So, I cannot to debug it by myself Following code: <? //load constantes if (is_file('config.php')) { require_once('config.php'); } //set charset ini_set("default_charset",'windows-1251');//utf-8 ini_set('display_errors', 1); set_time_limit(600); //create $MyArrayOfAvailItems=array(); for($i = 0; $i < 200; $i++) { $model_id = 5000+$i; //echo $model_id; //echo ' // '; array_push($MyArrayOfAvailItems, $model_id); } echo $MyArrayOfAvailItems[0]; echo ' '; echo sizeof($MyArrayOfAvailItems); echo ' '; $MyArrayOfFindedItems=array(); //$item_container = "bx_catalog_item_container"; $item_container = "Сожалеем"; /* Convert, target encoding, source encoding*/ $item_container = mb_convert_encoding($item_container, "windows-1251", "utf-8"); function populateArray2($model, $data) { global $model; global $data; global $item_container; global $recurse; global $MyArrayOfFindedItems; /* if ($recurse === 1) { echo $item_container; echo $data; echo 'hello world '.$model; echo ' '; } */ $pos = strpos($data, $item_container); //echo $pos; if ($pos !== false) { array_push($MyArrayOfFindedItems, $model); echo $model; echo ' '; //$recurse = 1; //populateArray2($model, $data, $recurse); } else { //echo 'not found'; } } foreach ($MyArrayOfAvailItems as $model) { //$item_id = 5121; //echo $model; //echo ' // '; $data = file_get_contents('https://ufopeople.ru/catalog/?q='.$model); //echo $data; //echo ' // '; $recurse = 0; populateArray2($model, $data); } //echo $data; echo ' '; echo memory_get_usage(true)."\n"; echo memory_get_peak_usage(true)."\n"; //echo sizeof($MyArrayOfFindedItems); /* foreach ($MyArrayOfFindedItems as $checkit) { echo ' '; echo $checkit; } */ In apache logs only [core:notice] [pid 20070] AH00052: child pid 17126 exit signal Segmentation fault (11) with timings, which are not correlate to me getting Error 500. I would appreciate any help. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 19, 2017 Share Posted November 19, 2017 PHP shouldn't segfault like that. Can you post a backtrace? Quote Link to comment Share on other sites More sharing options...
kicken Posted November 19, 2017 Share Posted November 19, 2017 In my experience, PHP segfaulting tends to be due to a stack overflow which happens when you try and make too many recursive function calls. First thing you need to do is clean up your code. Get rid of the global imports. Get rid of old commented-out code so it's not cluttering things up. Once you have some cleaned up code, if you still have problems then come back with the new code. Quote Link to comment Share on other sites More sharing options...
Areso Posted November 20, 2017 Author Share Posted November 20, 2017 (edited) Set up the core pattern (run this command as root):echo "<cores dir>/core-%e.%p" > /proc/sys/kernel/core_pattern make sure the directory is writable by PHP Set the ulimit (see above how to do it). Restart/rerun PHP. Well, PHP cannot write to core_pattern file. Moreover, I cannot change ownership (belongs to core_pattern) of the file. Operation not permitted. I tried to change ownership of the parent directory, but it doesn't work for me: /proc/sys# sudo chown :newdebug /kernel where debug is a group, created and fullfilled with root and www-data users (www-data runs PHP, from phpinfo()). Got the following error: changing group of ‘kernel’: Operation not permitted I run Ubuntu 14.04 LTS Should I use parameters instead of global imports? Or anything else? I don't know PHP at all, I just do it by reading articles. I do it for my sister, as she asks me to write a simple program for herself to get rid off boring part of her everyday work. First thing you need to do is clean up your code. Get rid of the global imports. Get rid of old commented-out code so it's not cluttering things up. Edited November 20, 2017 by Areso Quote Link to comment Share on other sites More sharing options...
requinix Posted November 20, 2017 Share Posted November 20, 2017 You need root or sudo to change kernel parameters, and you can choose whatever you want - like /tmp. $ echo "/tmp/core-%e.%p" | sudo tee /proc/sys/kernel/core_patternDon't try to chown or chmod anything in /proc or /kernel or other sensitive places like those. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.