2017-07-26 56 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); 
}