0

guys there are few topics about this kind of error and resolves, although my situation is that I have a cronjob what is doing some update queries into database with using multi queries requests. I set up to get error emails and I getting near 200 per day because of this memory issue. They are connected to :

system/application/libraries/MultiRequest/Handler.php. On line 132 :

while(CURLM_CALL_MULTI_PERFORM === curl_multi_exec($mcurlHandle, $activeThreads)) {

and also for :

system/application/libraries/MultiRequest/Request.php. On line 187 :

$responseData = curl_multi_getcontent($curlHandle);

I don't get one thing:

268435456 is bigger than 265556016, as also 268435456 than 265553811 and other mounts what I receiving. Can someone explain me why it's count that way or share link where I can read more about this.

Kind regards

Oleg Sapishchuk
  • 671
  • 5
  • 18
  • possible duplicate of [Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php](http://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-byte) – Halayem Anis Feb 03 '15 at 07:41
  • Try `ini_set('memory_limit', '-1');` top of this function. Check your memory settings in php.ini and check your code why this much memory is using. – Mansoorkhan Cherupuzha Feb 03 '15 at 07:47
  • I know how to fix, it's more about architecture of PHP. – Oleg Sapishchuk Feb 03 '15 at 08:04

2 Answers2

2

I would rather add this as a comment to Halayem Anis's comment as that's the answer but I can't yet. This is more of just an explanation.

When the error says "Could not allocate X bytes", this is in addition to the existing memory usage. If your PHP script is already using 200000000 bytes of memory and it tries to allocate 265556016 bytes, 265556016 + 200000000 would be 465556016 which is more than the memory limit of 268435456.

Your would need to configure the Multirequest to make fewer requests(I don't know the software but based on github it makes a bunch of CURL requests.) The other option is to configure the system to allow more memory for PHP. This is done either via the PHP.ini/ini_set file memory_limit option or something your host configures.

masshuu
  • 311
  • 1
  • 2
  • 6
  • So it's telling me that to existing storage what PHP is using it tries to allocate for example more 265556016. And if I have memory_limit set up to 2GB and already used 1GB it can't allocate. Am I right? – Oleg Sapishchuk Feb 03 '15 at 08:00
  • I would verify your cron is getting that memory_limit as the error suggests its only at 256MB. Typically cron jobs run on a different php.ini (/etc/php/cgi/php.ini or similar) so you may need to use the `--php-ini` flag to specify the location of your custom php.ini file. If your cron is `10 * * * * /usr/bin/php -f /path/to/file.php` add `--php-ini /path/to/custom/php.ini` to the end – masshuu Feb 03 '15 at 08:15
  • *When the error says "Could not allocate X bytes", this is in addition to the existing memory usage*, dude, that should def be more clear in the message! +1 – Wesley Smith May 11 '17 at 11:39
0

You need to allocate more memory for the script or for all the php configuration, you can do that in /etc/php5/cli/php.ini by modifying memory_limit = 256 to memory_limit = -1 means use all the memory you have if needed. Or you can use in your script ini_set('memory_limit', '512M');

PHP does not have (yet) a very intelligent garbage-colector and usualy all the memory is freed when the script is finished, usually I make skip, count type of scripts and from bash I am executing my scripts.

skip=0
count=0
while [ ! exiting_clause ]
do
   php script.php --skip="$skip" --count="$count"
   skip=$(($skip+$count))
done

This way I am iterating in all my data but in multiple instances, and usually you will gain some performance, and a lot less memory usage.

Alexandru Olaru
  • 5,860
  • 4
  • 21
  • 48
  • thank you for response, I know how to fix it. Thing is that I don't know core of the problem: Why if I have memory limit to 2GB and tried to use 1.91 GB I having that error. – Oleg Sapishchuk Feb 03 '15 at 08:02