2017-07-26 53 views
0

我開發了一個PHP腳本,它生成一個簡單的財務報告並通過SMTP(使用PHPMailer庫)發送它。PHP Azure WebJob - 失敗,退出代碼255(但在Kudu工作很好)

我嘗試使用Azure Web Jobs託管和執行腳本,但不幸的是每次運行它時都會失敗。

WebJob位於Azure上的wwwroot\App_Data\jobs\triggered\send-sales-report\send_sales_report.php

腳本內容如下;

wwwroot 
|___App_Data 
    |___jobs 
     |___triggered 
      |___send-sales-report 
       |___send_sales_report.php 
|___inc 
    |___class.EmailMessage.inc 
|___emails 
    |___sales_report.php 
|___E-Mail.php 

當我運行PHP WebJob使用:可以看出,該腳本導入了一些其他的腳本:

<?php 

    try 
    { 

     include "./../../../../inc/class.EmailMessage.inc"; 
     include "./../../../../E-Mail.php"; 

     $message = new EmailMessage('sales_report', array()); 
     SendOrderEmail('Sales Report', $message->render(), '[email protected]', 'Recipient Name'); 

    } 
    catch (Exception $e) 
    { 

     echo 'Caught exception: ', $e->getMessage(), "\n"; 

    } 

?> 

此外,上述文件的目錄結構如下Azure Portal(無論是手動還是按計劃),它都會失敗,退出代碼爲255;但是,當我在Azure上使用Kudu控制檯執行腳本時,它工作得很好。另外,我也在本地複製了運行環境並且工作正常。

任何幫助,非常感謝。

回答

1

我會建議你爲你的應用程序啓用PHP錯誤日誌。創建.user.ini文件,並添加以下代碼行:

log_errors = on

參見我這篇文章:Enable PHP error logging

的PHP錯誤日誌的默認位置是:D:\home\LogFiles\php_errors.log

這應該有助於進一步處理。

1

255是一個錯誤。見PHP exit status 255: what does it mean?。所以,您可能會在PHP腳本中遇到致命錯誤。

有可能通過using register_shutdown_function function發現致命錯誤。以下代碼示例可用於記錄發生的致命錯誤。

<?php 

register_shutdown_function('shutdown_function'); 

try 
{ 

    include "./../../../../inc/class.EmailMessage.inc"; 
    include "./../../../../E-Mail.php"; 

    $message = new EmailMessage('sales_report', array()); 
    SendOrderEmail('Sales Report', $message->render(), '[email protected]', 'Recipient Name'); 

} 
catch (Exception $e) 
{ 

    echo 'Caught exception: ', $e->getMessage(), "\n"; 

} 

function shutdown_function() 
{ 
    $e = error_get_last(); 
    print_r($e); 
}