简体   繁体   English

cronjob php中的新实例

[英]New instance in a cronjob php

I want to execute a periodic task using a php script. 我想使用php脚本执行定期任务。

Inside my script (into my cron job), I am trying to instantiate a class without success: 在我的脚本(进入我的cron工作)中,我试图实例化一个类而没有成功:

The include works fine: 包括工作正常:

include_once (dirname(__FILE__).\\'../my/class/MyObjectMgrClass.php\\');

But as soon as I try to instantiate the class, the cron does not work anymore: 但是,一旦我尝试实例化该类,则cron不再起作用:

$myObjectMgr = new MyObjectMgr();

"include_once()" try to include the file you define but won't stop the script if it doesn't exists Try to use require_once(), it will trigger a fatal error if the file is missing. “ include_once()”尝试包含您定义的文件,但是如果不存在该脚本,则不会停止该脚本。尝试使用require_once(),如果该文件丢失,它将触发致命错误。 by the way when your concatenate with dirname, add and / to the begin of the string like 顺便说一下,当用dirname连接时,在字符串的开头添加和/

 require_once (dirname(__FILE__)). '/../my/class/MyObjectMgrClass.php';

Also don't use the \\ unless you want to escape something. 也不要使用\\,除非您想转义某些内容。

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

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