PHP exec to run cron file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
benjam1nrk
Forum Newbie
Posts: 2
Joined: Tue Jun 23, 2009 3:34 pm

PHP exec to run cron file

Post by benjam1nrk »

Hello,

I have a video conversion php file which runs via cron to execute a video conversion queue. Works perfectly when run with via cron, or executed directly from browser. For obvious reasons, the cron file is not accessible through the web, and is secured with htaccess.

I would like to give the administrator the ability to manually run the video conversion php cron file. I have attempted the code:

Code: Select all

 
exec("php -q /home/me/public_html/cronfile.php");
which is included in a php file which would be executed through an ajax call.

When the php file is executed in this manner, it does not appear to exit and continuously consumes system memory without accomplishing its mission.. Calling the file via cron works perfectly, why the memory leak when calling with php exec?

Thanks for any feedback, I must be missing something..

Also can not simply "include" the file, as it is called from a function which is initiated via AJAX.

The command "php -q /home/me/public_html/cronfile.php" works fine when executed from the shell, am only receiving memory leak when run with php exec.
Last edited by Benjamin on Tue Jun 23, 2009 11:39 pm, edited 1 time in total.
Reason: Changed code type from text to php.
patrickmvi
Forum Commoner
Posts: 32
Joined: Mon Jun 22, 2009 6:45 am
Location: Fort Lauderdale, FL

Re: PHP exec to run cron file

Post by patrickmvi »

The issue may be related to permissions. When you exec a php script it assumes the permissions of whatever the web server is running as (usually nobody) and the nobody user has very restricted permissions. When you run stuff from the cron, it runs under whatever user's cron it's set up for. Perhaps this is the source of your problems. What you'd probably want to do is capture any output coming from it and see if it returns any errors. Depending on your access privileges to the server, you may be able to "su" to the web server user and try to run your script and see any errors that might come up.
benjam1nrk
Forum Newbie
Posts: 2
Joined: Tue Jun 23, 2009 3:34 pm

Re: PHP exec to run cron file

Post by benjam1nrk »

I am able to run the php file directly from the web with no problems, wouldn't it be running under the user "nobody" in this instance as well?
patrickmvi
Forum Commoner
Posts: 32
Joined: Mon Jun 22, 2009 6:45 am
Location: Fort Lauderdale, FL

Re: PHP exec to run cron file

Post by patrickmvi »

I thought you had mentioned that it wasn't accessible via the web. You are correct then, the permissions should be the same. It may be a path issue then, when you're trying to run it via the web, are you doing it from the same folder where it actually resides? Also, have you tried including the full path to php in your exec statement?
Post Reply