I have a dreamhost web panel and I am setting a cronjob to run my php script, but it shows weird errors, it looks like that it's not executing the file , but it's reading the file. The error is shown below, it comes as email to me
?php: No such file or directory [somesessionvariable]=1573: command not found line 3: syntax error near unexpected token
"include/mydb.php"' line 3:
require_once("include/mydb.php");
This is the subject of the mail:
Cron /usr/local/bin/setlock -n /tmp/cronlock.3782446772.128284 sh -c $'/path /to/file/cases_cron.php'
the permission of the file is 755 and i have copied the path from other perfectly running cronjobs, so no issue to the file path as it's getting the file contents. I am not getting where the problem is
I should try to use an absolute path to your include file.
I'm sure the problem is about the include path not being set the same in file call and cron call.
You can do something like this :
require_once dirname(__FILE__)."/include/mydb.php";
__FILE__
is the path of the file where this line is executed, dirname()
return the absolute path where the file is located.
Of course, you can use, as you want require
, require_once
, include
, include_one
Your paths are probably off. Try to either avoid relative paths (include/file.php instead of /var/www/project/include/file.php) or change your working directory with chdir() .
您也可以在您的cronjob中输入“ cd”命令,即:
cd /path/to/phpfile && php -f file.php
Ok, Guys, Thanks for all of your support, I am finally able to sort out the matter.
I was missing the following line on the top of the file
#!/usr/local/bin/php
Adding this line at the top of the php file, sorted my problem. But i don't know that what this line means to the script. But i copied it from other working crons.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.