简体   繁体   English

Openshift Cron无法运行php文件

[英]Openshift cron doesn't run php file

I have 2 .php files in my application - book.php and weather.php. 我的应用程序中有2个.php文件-book.php和weather.php。 I create a file named "runscript" in /.openshift/cron/minutely. 我在/.openshift/cron/minutely中创建一个名为“ runscript”的文件。 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. 但是,如果我只是通过Web浏览器运行此脚本(转到http://xxx-xxxxxxx.rhcloud.com/book.php ),那么我就收到了消息。 How is it possible? 这怎么可能? Magic? 魔法?

Did you miss the #!/bin/bash part? 您是否错过了#!/bin/bash部分? That's needed to run the shell script. 这是运行shell脚本所必需的。

For why your cron job is not executing, check the cron logs on OpenShift. 有关为什么您的cron作业未执行的原因,请检查OpenShift上的cron日志。 You can find them at ~/app-root/logs/cron_*.log when you SSH into your gear. SSH进入设备时,您可以在~/app-root/logs/cron_*.log找到它们。

Make sure your cron job is execuable with chmod , and has the shebang line as @gnaanaa says. 确保您的cron作业可以使用chmod ,并且具有@gnaanaa所说的shebang行。 Also check if you have one of the .openshift/cron/minutely/jobs.{allow,deny} files as they may cause cron to skip your job. 另外,请检查您是否拥有.openshift/cron/minutely/jobs.{allow,deny}文件之一,因为它们可能会导致cron跳过您的工作。 (See the cron README for more information.) (有关更多信息,请参见cron自述文件 。)

And after your cron job is working, you can get rid of the wrapper script runscript and have cron call book.php directly. 而你的cron作业工作后,你可以摆脱包装脚本的runscript ,并有cron的通话book.php直接。 To do so, place book.php directly into .openshift/cron/minutely , make it executable, and add this shebang to it: 要做到这一点,地方book.php直接进入.openshift/cron/minutely ,使其可执行,这家当添加到它:

#!/usr/bin/env php

Hope this helps. 希望这可以帮助。

I use openshift aswell and executed a php file with a cron aswell. 我也使用openshift并用cron执行了php文件。

#!/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. 问题是,无法加载所有必需的php文件,因为工作目录与Web服务器加载时的工作目录不同。 Setting the working directoy in the php script itself will prevent this error and makes the script perfectly executable by the cron. 在php脚本本身中设置有效的Directoy可以防止此错误,并使脚本可以由cron完美执行。

This should help some people to get their script running. 这应该可以帮助某些人使其脚本运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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