-1

I am using this in cron File so that it will slow my system ini_set('memory_limit', '-1');. Again and again I have created a cron PHP script which is called recursively. It is giving me this error:

Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes)

I have seen some solutions like increasing the size of memory allocation limit in php.ini. But this is not a permanent solution, and I want permanent solution for this. How can I delete the address of previous stack memory?

Alexander Mikhalchenko
  • 4,315
  • 3
  • 28
  • 54
  • Can you show your code and your cronjob? There's not enough info here to solve it. Now, you CAN set the memory limit from inside the script: `ini_set('memory_limit', '128M');`, and I will note that your default of 32M is a bit small. – Will Feb 02 '16 at 12:38
  • 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) – Alexander Mikhalchenko Feb 02 '16 at 12:40
  • I have already said ini_set is not permanent solution already tried this. so please any thing else – Ghanshyam Kumar Feb 02 '16 at 12:41
  • @GhanshyamKumar you should've checked other answers http://stackoverflow.com/a/5254547/2044039 . editing php.ini is a permanent solution whilst setting options with ini_set isn't. – Alexander Mikhalchenko Feb 02 '16 at 12:43
  • @AlexanderM. yes i have seen this problem on many other questions but i have using thing in cron file. its not gives me appropriate solution.Beacause I have already used this at `ini_set('memory_limit', '-1');` it will slow the system because of memory.... – Ghanshyam Kumar Feb 02 '16 at 12:43
  • We can't give you an appropriate solution without knowing what is causing the problem. Is it badly written code? What is using large amounts of memory? Are you building large arrays in memory? How can we tell when we can't see what your code is doing or how it works? You want a solution, you have to provide us with sufficient information to identify the problem. – Mark Baker Feb 02 '16 at 12:47
  • And why are you running a cron script recursively? – Mark Baker Feb 02 '16 at 12:47
  • @MarkBaker I did'nt use any array, I am using only variables with recursive, recursice function for synchronize the database of local server to main server – Ghanshyam Kumar Feb 03 '16 at 09:26

1 Answers1

0

Editing php.ini is a permanent solution whilst setting options with ini_set isn't.

For cronjobs executed you specify in crontab, in order to configure php options for cli, you should edit the proper ini file.

If php-SAPI.ini exists (where SAPI is the SAPI in use, so, for example, php-cli.ini or php-apache.ini), it is used instead of php.ini. The SAPI name can be determined with php_sapi_name().

(Docs)

To get the loaded ini file location, execute:

$ php -i | grep ini
Configuration File (php.ini) Path => /usr/local/etc/php/5.6
Loaded Configuration File => /usr/local/etc/php/5.6/php.ini

So, in my case, to set memory limit for cron, I would edit /usr/local/etc/php/5.6/php.ini.

Alexander Mikhalchenko
  • 4,315
  • 3
  • 28
  • 54