简体   繁体   中英

Openshift cron doesn't run php file

I have 2 .php files in my application - book.php and weather.php. I create a file named "runscript" in /.openshift/cron/minutely. This file contents:

#!/bin/bash

php -f $OPENSHIFT_REPO_DIR/weather.php

This script send me message to phone every minute, it's OK. Then I replace to:

php -f $OPENSHIFT_REPO_DIR/book.php

This script MUST send me message too, but nothing is happing. But if I just run this script by my webbrowser (go to the http://xxx-xxxxxxx.rhcloud.com/book.php ) so I got my message. How is it possible? Magic?

Did you miss the #!/bin/bash part? That's needed to run the shell script.

For why your cron job is not executing, check the cron logs on OpenShift. You can find them at ~/app-root/logs/cron_*.log when you SSH into your gear.

Make sure your cron job is execuable with chmod , and has the shebang line as @gnaanaa says. Also check if you have one of the .openshift/cron/minutely/jobs.{allow,deny} files as they may cause cron to skip your job. (See the cron README for more information.)

And after your cron job is working, you can get rid of the wrapper script runscript and have cron call book.php directly. To do so, place book.php directly into .openshift/cron/minutely , make it executable, and add this shebang to it:

#!/usr/bin/env php

Hope this helps.

I use openshift aswell and executed a php file with a cron aswell.

#!/bin/bash
php ${OPENSHIFT_REPO_DIR}index.php

This executes the script normally at first sight. However no output was produced. The problem was, that all the required php files couldnt be loaded because the working directory was not the same as it would be when loaded by the webserver. Setting the working directoy in the php script itself will prevent this error and makes the script perfectly executable by the cron.

This should help some people to get their script running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM