Page 1 of 1

PHP exec to run cron file

Posted: Tue Jun 23, 2009 3:36 pm
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.

Re: PHP exec to run cron file

Posted: Tue Jun 23, 2009 3:48 pm
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.

Re: PHP exec to run cron file

Posted: Tue Jun 23, 2009 4:19 pm
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?

Re: PHP exec to run cron file

Posted: Tue Jun 23, 2009 10:24 pm
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?