richid Posted December 21, 2006 Share Posted December 21, 2006 Hey all,I'm having a problem running a script from the command line. For context, I'm getting a list of ~20k items from a DB, iterating through and making 2 calls to a remote API for each item. The first call is to get the description, and the second call is to update the information. The problem is, after each iteration the memory usage keeps increasing. I've unset all applicable variables and I am not making any other calls, but I can't seem to figure out where the problem is. I've also tried using get_defined_vars(), and the only one returned is the $ids array. Here is my code:[code]$count = count($ids);for($i = 0; $i < $count; $i++) { print "start_loop_mem:\t\t" . (memory_get_usage() / 1024 / 1024) . " MB\n"; $api = new api(); $result = $api->get_item($ids[$i]['id']); $desc = $result['Item']['Description']; unset($result); print "after_api_call_mem:\t" . (memory_get_usage() / 1024 / 1024) . " MB\n"; if($ids[$i]['shipping'] == 0) { $desc = preg_replace("@Shipping@is", "Free Shipping" ", $desc); } else { $desc = preg_replace("@Shipping@is", $ids[$i]['shipping'], $desc); } $desc = preg_replace("@Price", $ids[$i]['price'], $desc); $update_args = array('Price' => $ids[$i]['price'], 'Description' => '<![CDATA[' . $desc . ']]>', 'Shipping' => $ids[$i]['shipping']); print "after_update_args_mem:\t" . (memory_get_usage() / 1024 / 1024) . " MB\n"; $result = $api->update_item($ids[$i]['id'], $update_args); print "bottom_loop_mem:\t" . (memory_get_usage() / 1024 / 1024) . " MB\n"; unset($api); unset($result); unset($ids[$i]); unset($update_args); unset($desc);[/code]And here are the results:[code]start_loop_mem: 7.9615097045898 MBafter_api_call_mem: 8.0777969360352 MBafter_update_args_mem: 8.1437377929688 MBbottom_loop_mem: 8.1848983764648 MBstart_loop_mem: 8.1417083740234 MBafter_api_call_mem: 8.242057800293 MBafter_update_args_mem: 8.3129806518555 MBbottom_loop_mem: 8.3567886352539 MBstart_loop_mem: 8.3102798461914 MBafter_api_call_mem: 8.4185485839844 MBafter_update_args_mem: 8.494987487793 MBbottom_loop_mem: 8.5417327880859 MB[/code]As you can see, it will continue on like this until memory_limit is reached and error out. Any ideas or help as to what could be causing this would be greatly appreciated!Thanks,Rich Link to comment https://forums.phpfreaks.com/topic/31503-command-line-memory-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.