[英]php cron job not working running script from CLI works fine
I have a script which drives something in Suite CRM which I can run easily from the command line by just typing php script.php. 我有一个脚本可以在Suite CRM中驱动一些东西,只需输入php script.php就可以从命令行轻松运行。
However when I run it using the cron, it fails after the line 但是当我使用cron运行它时,它在行之后失败
echo "Defined sugarEntry\n";
I have also tried hard coding the path in the require statements and also tried require_once. 我也试过在require语句中对路径进行硬编码,并尝试了require_once。
I've also set the relevant include path in /etc/php.ini, and this is the php that is being used in the cron. 我还在/etc/php.ini中设置了相关的包含路径,这是在cron中使用的php。 Is there anything else I am missing?
还有什么我想念的吗?
<?php
//Don't forget to set the include path in /etc/php.ini
echo "Start \n";
set_include_path(get_include_path() . PATH_SEPARATOR . $full_path);
echo "Include path set to " . get_include_path()."\n";
//error_reporting(E_ERROR);
if(!defined('sugarEntry'))
define('sugarEntry', true);
echo "Defined sugarEntry\n";
require( 'include/entryPoint.php');
echo "Entry point included\n";
require( 'custom/modules/Accounts/controller.php');
echo "Include file set\n";
$controller = new AccountsController();
echo "AccountsController initialised\n";
//$controller->debug = true;
//Loop through all the Accounts records that are a customer
$controller->sync_all_crm_to_smb();
echo "Finished\n";
?>
Instead of configuring the necessary paths why don't you try with an easier way. 而不是配置必要的路径,为什么不尝试更简单的方法。 You can do the following in your crontab:
您可以在crontab中执行以下操作:
*/1 * * * * cd <path_to_your_script> & php <script_name>.php
I'm using */1 * * * * just for the example. 我正在使用* / 1 * * * *作为示例。
<path_to_your_script>
is the path to the directory where you successfully execute the script through the console. <path_to_your_script>
是通过控制台成功执行脚本的目录的路径。
If this still doesn't solve your problem try this in your php script: 如果这仍然无法解决您的问题,请在您的php脚本中尝试:
#!/usr/local/bin/php
<?php
.......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.