我正在尝试在我的AWS EC2实例上设置一个cronjob。 crontab文件中的实际条目没有错,但是当我尝试在命令行中运行命令时,我得到了这个响应。
PHP Warning: include(../scripts/connect.php): failed to open stream: No such file or directory in /var/www/htdocs/crons/emailnotifications.php on line 2 PHP Warning: include(): Failed opening '../scripts/connect.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/htdocs/crons/emailnotifications.php on line 2 PHP Warning: include(../scripts/functions.php): failed to open stream: No such file or directory in /var/www/htdocs/crons/emailnotifications.php on line 3 PHP Warning: include(): Failed opening '../scripts/functions.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/htdocs/crons/emailnotifications.php on line 3 PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for 'UTC/0.0/no DST' instead in /var/www/htdocs/crons/emailnotifications.php on line 4 PHP Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /var/www/htdocs/crons/emailnotifications.php on line 6 PHP Warning: mysql_query(): A link to the server could not be established in /var/www/htdocs/crons/emailnotifications.php on line 6 PHP Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /var/www/htdocs/crons/emailnotifications.php on line 7
我可以加载这个页面在我的浏览器,它可以正常工作,但不是从命令行(或cronjob)。
包括(../脚本/ connect.php)
您的脚本正在使用相对目录。 这些链接到当前的工作目录。 当cron运行时,你的CWD几乎肯定不是你想象的那样。 要么在您的cron脚本中设置CWD,要么更新您的PHP代码以使用相对于自己的path。 就像include(realpath(dirname(__FILE__).'/../scripts/connect.php'))或许?
其余的问题也是,几乎可以肯定的是你的cron会话的具体环境与web服务器运行脚本时的环境有所不同。 找出差异,并解决它们。