[英]Run php script with cronjob
so this is my cronjob 这是我的工作
PATH=/package/host/localhost/php-5.4.7-1/bin:/bin:/usr/bin
PHPRC=/home/stuff/etc
* * * * * php /home/stuff/private/xFEklnTekl/cmd.php
and this is the cmd.php file 这是cmd.php文件
<?php
$c = file("c.txt");
$f = fopen("c.txt", "w+");
$g = $c[0]+1;
fwrite($f, $g);
fclose($f);
?>
Sadly it doesn't update the c.txt file as it should. 遗憾的是,它没有按原样更新c.txt文件。 I think something is wrong with the given path in the php script.
我认为php脚本中的给定路径出了问题。 I've already tried just /c.txt but it didn't work either.
我已经尝试过/c.txt,但是也没有用。 So, what might be wrong?
那么,可能出什么问题了?
Your crontab shouldn't contain anything apart from cronjobs. 除cronjobs外,您的crontab不应包含任何内容。 Try using this:
尝试使用此:
* * * * * /bin/php /home/stuff/private/xFEklnTekl/cmd.php
And be sure you have +x permissions to execute, as well as crontab user has access to the directory. 并且确保您具有执行权限,并且crontab用户有权访问该目录。
Also, put full paths in 另外,在
$c = file("c.txt");
$f = fopen("c.txt", "w+");
to 至
$c = file("/home/stuff/private/xFEklnTekl/c.txt");
$f = fopen("/home/stuff/private/xFEklnTekl/c.txt", "w+");
Edit As seen on the comments, instead of /bin/php
you have to use whatever comes from which php
. 编辑如注释所示,您必须使用
/bin/php
来代替/bin/php
which php
。 In your case, 就你而言
* * * * * /package/host/localhost/php-5.4.4/bin/php /home/stuff/private/xFEklnTekl/cmd.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.