2012-10-31 56 views
0

我有下面的代碼,我在cron運行,cron作業不執行和返回錯誤

<?php 
    $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__); 
    $directory = $_SERVER["DOCUMENT_ROOT"]."/cron/"; 
    $file = "register_warranty_". date("dMY") .".csv"; 
    $filepath = $directory.$file; 

    if(!file_exists($filepath)) 
    { 
     $fp = fopen($filepath, "w+"); 
     fwrite($fp, "Title, Initials, Surname, HomeTel, Mobile, HouseNumber, Address, Address2, Town, Postcode, NewlyBuiltHome, InstallationDate, Houseowner, InstallersName, InstallersEmail, InstallersMobile, InstallersGasSafeNumber, BusinessName, BusinessAddress, BusinessAddress2, BusinessTown, BusinessRegion, BusinessPostcode, BusinessGasSafeNumber, BusinessEmail, SuppliersName, Model, serial, MaintenanceContract, ExpiryDate, Donotwishtobecontactedviapost, Donotwishtobecontactedviatelephone, Donotwishtobecontactedviaemail, Donotwishtobecontactedviasms\n"); 
     fclose($fp); 
    } 

>

在克龍的電子郵件運行的cron當我 - 我得到以下錯誤,

線1:PHP:沒有這樣的文件或目錄
線3:鄰近語法錯誤意外的標記('
line 3:
$ _SERVER [ 'DOCUMENT_ROOT'] =目錄名(FILE);'

我在做什麼明顯錯誤,我不是最有經驗的克倫工作。

回答

0

我想你忘了在cronjob中的文件名之前加上php命令。

php myscript.php

+0

在/ usr/bin中/ PHP -f myscript.php應該用來代替PHP myscript.php [/ usr/bin /是執行php的示例路徑,找到你的..在shell中輸入哪個php] – donald123

1

你可以做的兩兩件事之一:

  1. crontab執行你的PHP腳本:

    /usr/bin/php -q script.php

  2. 在開始添加shebang線你的PHP腳本:

    #!/usr/bin/php -q

    並給予執行權限的腳本:

    chmod +x script.php