PHP的问题包括来自命令行(或cronjob)的问题

PHP的问题包括来自命令行(或cronjob)的问题,php,linux,amazon-ec2,cron,sysadmin,Php,Linux,Amazon Ec2,Cron,Sysadmin,我正在尝试在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():

我正在尝试在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)加载。

查看此路径:/var/www/htdocs/crons/emailnotifications.php
我认为没有emailnotifications.php文件。所以这个文件不包括在内。如果未包含此文件,则会出现其他错误

请使用要包含的文件的绝对路径

使用以下方式:-

include(require dirname(__FILE__) .'/../scripts/connect.php');
require_once dirname(__FILE__) . '/../inc/function.php';

你为什么不试着读一下错误信息呢?@CharlotteDunois我已经解释过了,我已经检查过文件是否存在。此外,该脚本在从浏览器运行时也可以工作。您可以通过始终使用绝对文件路径来避免那些包含错误。并在脚本顶部设置默认时区。我唯一的问题是为什么它不能连接到MySQL。@CharlotteDunois问题是错误日志说它找不到连接文件。虽然我知道它是绝对的文件路径。问题解决了。