Cron作业不运行,但http://file.php从浏览器运行良好? [英] Cron jobs not running but http://file.php runs fine from browser?
问题描述
< ;??>
而不是< ;?
所以基本上,当我在浏览器中输入网址时,http://site.com/file .php它运行正常(这是一个mysql备份+通过电子邮件发送)。但是当我尝试使用cron运行相同的文件时,我会收到错误...
我的服务器在MediaTemple上,cron是:
php -c /home/xxxxxxx/domains/xxxxxxxxxxxxxx.com/html/777/fnc/filenamexxxxxx.php - 'bckup = 1'
这是错误:
PHP:语法错误, ('in /nfs/c08/h02/mnt/xxxxxxx/domains/xxxxxxxxxxxxxxxxx.com/html/777/fnc/filenamexxxxxx.php第2行)
这是代码的第一部分(因为它是,没有编辑,除了网站地址+电子邮件):
<?php
// envoi un courriel de tous les rv des 7 prochains jours pour chaque cliniqueàtoutes les 30min(cron scriptlancépar cpanel)
session_start();
$ bypass = 1;
// $ _ SESSION ['rep'] =777 /;
include_once(inc_includes_principaux.php);
// error_reporting (E_ERROR);
//通过电子邮件发送自动备份,只需使用CRON链接到此文件:
if($ _GET ['bckup']){
// va chercher les infos de connection
include_once('inc_bd_connexion.php');
// get cliniques
$ cliniques = _get_clinique_info(); // _ p($ cliniques); _ x();
$ date = date('Ymd');
$ date7jours = _get_x_days_before($ date,7,'+'); // _ e($ date7jours); _ x();
//迭代诊所并发送电子邮件
foreach($ cliniques as $ cliniqueid => $ v){
$ emailthis = _get_rv_printformat $ date,$ date7jours,$ cliniqueid); // start,end,id
//发送电子邮件给用户
_email('emailaddressxxxxxxxx',$ emailthis,'LCJG - Horaire de' 。$ v ['A29']。'du'._date_en_texte($ date)。'au'._date_en_texte($ date7jours),'emailaddressxxxxxxxx');
sleep(1); //给服务器一个断点并让一些其他任务执行
_email('emailaddressxxxxxxxx',$ emailthis,'LCJG - Horaire de'。$ v ['A29'] 。'du'._date_en_texte($ date)。'au'._date_en_texte($ date7jours),'emailaddressxxxxxxxx');
unset($ emailthis);
echo'LCJG - Horaire de< b>'。$ v ['A29']。'< / b> 。< br>';< br>
}
}
?>`
解决方案为了避免更改我的代码,因为我想要一个容易实现的解决方案,我遵循Dagon建议使用wget,而是使用CURL。所以我可以保持我的代码,就像它是,只是调用我的文件,以便在特定的时间执行它。
没有改变我的脚本的代码是:
curl www.aaaaaaa.com/file-to-execute.php?arg=1
这样,cron运行得很好,现在一切都很好。感谢您的帮助!
I've read here on Stackoverflow that paths inside the file could be a problem, but it seems to fail at the first thing it read... Other than this I have no clue, even after checking many questions/answers here. At some point I thought it was because I used a shorthand version of PHP tag ("<? ?>
" instead of "<?php ?>
").
So basically, when I type the url in a browser "http://site.com/file.php" it runs fine (it's a mysql backup + send by email). But when I try to run the same file with cron, I get errors...
My server is on MediaTemple, the cron is:
php -c /home/xxxxxxx/domains/xxxxxxxxxxxxxx.com/html/777/fnc/filenamexxxxxx.php --'bckup=1'
Here is the error:
PHP: syntax error, unexpected '(' in /nfs/c08/h02/mnt/xxxxxxx/domains/xxxxxxxxxxxxxxx.com/html/777/fnc/filenamexxxxxx.php on line 2
Here's the first part of the code (as it is, no edit, except website address + emails):
<?php
// envoi un courriel de tous les rv des 7 prochains jours pour chaque clinique à toutes les 30min (cron script lancé par cpanel)
session_start();
$bypass = 1;
//$_SESSION['rep'] = "777/";
include_once("inc_includes_principaux.php");
//error_reporting(E_ERROR);
// to send an automated backup by email, just link to this file like this with CRON:
if ($_GET['bckup']){
// va chercher les infos de connection
include_once('inc_bd_connexion.php');
// get cliniques
$cliniques = _get_clinique_info();//_p($cliniques);_x();
$date = date('Ymd');
$date7jours = _get_x_days_before($date, 7, '+');//_e($date7jours);_x();
// iterate cliniques and send email
foreach ($cliniques as $cliniqueid => $v) {
$emailthis = _get_rv_printformat($date, $date7jours, $cliniqueid);// start, end, id
// send email to users
_email('emailaddressxxxxxxxx', $emailthis, 'LCJG - Horaire de '.$v['A29'].' du '._date_en_texte($date).' au '._date_en_texte($date7jours),'emailaddressxxxxxxxx');
sleep(1);//give a break to the server and let some other tasks execute
_email('emailaddressxxxxxxxx', $emailthis, 'LCJG - Horaire de '.$v['A29'].' du '._date_en_texte($date).' au '._date_en_texte($date7jours),'emailaddressxxxxxxxx');
unset($emailthis);
echo 'LCJG - Horaire de <b>'.$v['A29'].'</b> pour les 7 prochains jours envoyé par courriel.<br>';
}
}
?>`
解决方案 To avoid changing my code and since I wanted an easy to implement solution, I followed Dagon suggestion to use wget, but instead used CURL. So I could keep my code exactly as it was and just call my file in order to execute it at a specific time.
The code that worked without making changes to my script is:
curl www.aaaaaaa.com/file-to-execute.php?arg=1
And with this, the cron ran perfectly and now everything is fine. Thanks all for your help!
这篇关于Cron作业不运行,但http://file.php从浏览器运行良好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!