/etc/php.ini file
memory_limit = 8M ; Maximum amount of memory a script may consume (8MB)
change the line to a higher value (have it at a safe limit though)
Main Topics
Browse All TopicsHi,
I've got some code that is to process images in the background. I'm making a cron-job for this wich I will be running from the command line.
The code works just fine when I request the script via de web (via Apache), but it crashes when I run it from the command line.
The crash happens on this line:
$this->original_handle = imagecreatefromjpeg($this-
Where I believe that the function imagecreatefromjpeg is the problem.
I think the problem is caused by lack of memory, when requested from the web I use the attached function to increase the memory in PHP to be able to process the image.
I don't use this function on the command line, because when I do it crashes on the line I marked.
How can I adjust my code so it also works on the command line?
Why doesn't it work on the command line?
The last is also interesting for me, as I got a similar problem for another cronjob that fails to send out emails from the command line.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The script crashes on the command line, there is no time limit when running a php script from the command line. The script works fine when requested via Apache, but it is a cronjob.
See: http://nl2.php.net/command
Also, I've verified that the script actually crashes on the lines I pointed out. Simply by putting a print-command just before and after. Only the one before is displayed.
I can find 3 php.ini files, one of them is a backup and isn't used.
The other 2 have the memory_limit setting set to 64M and 32M; both of them I think should be enough to process a file.
Alltough it could be I need even more (even though the files are relatively small).
The code snippet I posted earlyer I use to increase the memory for resizing an image when accessing the script via the web, it works fine there. But when I use that code on the command line, it crashes on the marked line. Perhaps that points to a problem ??
I had a similar problem in the past, where the script crashed when the jpg-function was called; this was solved by increasing the memory with the function I posted earlyer.
Now I run the same code from the command line.
When I use the function to increase the memory, the function itself crashes.
When I bypass the function on the command line it crashes on the jpg-function.
The same script works fine when requested via apache.
Unfortunatly I can't simply copy the ini file over the other file, as that might impact a running system to much and may create some big problems.
As far as I know there isn't an error message, the script simply stopt. I've got an error handler in place wich sends an email when an error occurs, and I'm not getting an email.
Where and how does PHP "dump" it's error messages when run from the command line? I'll look into retrieving some error message tomorrow; if anyone has a suggestion on how to retrieve that in the mean time, please post it; saves me a lot of time.
Yes, there are multiple processes running in the background, just trying to copy the php.ini file is not an option, this could have a big impact on those processes wich is simply not acceptable on a production server.
The other php.ini file is related to the plesk-admin-panel and is used for the secure webserver that is needed for that. So, it won't affect the command line settings.
Function works like a charm, I can get the memory usage at the moment.
Turns out the call "ini_get('memory_limit');"
I tried to cope with this by using setting the limit variable manually in my increase function, I even tried it setting it to 0.
But the whole script still crashes still at
$this->original_handle = imagecreatefromjpeg($this-
I tried out a script I attached.
When I run this as root I get the following:
string(3) "64M"
string(3) "64M"
When I run this as non-root I get the following:
string(2) "8M"
string(4) "100M"
When I run this via apache I get the following:
string(3) "64M"
string(4) "100M"
Seems that I'm unable to change the memory limit when running as root.
PHP version has been upgraded.
Resulted in me having to update some code throughout the software, but all that was done with relative ease.
The script now works fine and does exactly what it needs to do. I think some bug fixes in PHP where the actual cause for fixing this problem. Alltough the suggested function is in use at the moment, otherwise it would fail the moment the function would be used.
Some other minor problems have also been resolved automagicly by the upgrade. I can recommend an upgrade any time ;-).
Now for the database crash to be solved! But that's a different ballgame.
points awarded to the suggested function, as it was definatly needed.
Business Accounts
Answer for Membership
by: ygouthamPosted on 2008-02-14 at 00:36:08ID: 20891824
the php.ini file has a maximum limit to set the memory used by a particular script. increase the value to a suitably high value to run your script and you should be done