Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to reduce virtual memory by optimising my PHP code?
    text
    copied!<p>My current code (see below) uses 147MB of virtual memory! My provider has allocated 100MB by default and the process is killed once run, causing an internal error. The code is utilising curl multi and must be able to loop with more than 150 iterations whilst still minimizing the virtual memory. The code below is only set at 150 iterations and still causes the internal server error. At 90 iterations the issue does not occur.</p> <p>How can I adjust my code to lower the resource use / virtual memory?</p> <p>Thanks!</p> <pre><code>&lt;?php function udate($format, $utimestamp = null) { if ($utimestamp === null) $utimestamp = microtime(true); $timestamp = floor($utimestamp); $milliseconds = round(($utimestamp - $timestamp) * 1000); return date(preg_replace('`(?&lt;!\\\\)u`', $milliseconds, $format), $timestamp); } $url = 'https://www.testdomain.com/'; $curl_arr = array(); $master = curl_multi_init(); for($i=0; $i&lt;150; $i++) { $curl_arr[$i] = curl_init(); curl_setopt($curl_arr[$i], CURLOPT_URL, $url); curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_arr[$i], CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl_arr[$i], CURLOPT_SSL_VERIFYPEER, FALSE); curl_multi_add_handle($master, $curl_arr[$i]); } do { curl_multi_exec($master,$running); } while($running &gt; 0); for($i=0; $i&lt;150; $i++) { $results = curl_multi_getcontent ($curl_arr[$i]); $results = explode("&lt;br&gt;", $results); echo $results[0]; echo "&lt;br&gt;"; echo $results[1]; echo "&lt;br&gt;"; echo udate('H:i:s:u'); echo "&lt;br&gt;&lt;br&gt;"; usleep(100000); } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload