[英]PHP Azure WebJob - Failing With Exit Code 255 (But Working Fine On Kudu)
我已经开发了一个PHP脚本,该脚本可以生成简单的财务报告,并通过SMTP(使用PHPMailer库)发送报告。
我正在尝试使用Azure Web Jobs托管和执行脚本,但是不幸的是,每次运行该作业都会失败。
WebJob位于Azure上的wwwroot\\App_Data\\jobs\\triggered\\send-sales-report\\send_sales_report.php
中。
该脚本的内容如下: 可以看出,该脚本导入了许多其他脚本:
<?php
try
{
include "./../../../../inc/class.EmailMessage.inc";
include "./../../../../E-Mail.php";
$message = new EmailMessage('sales_report', array());
SendOrderEmail('Sales Report', $message->render(), 'name@emailprovider.com', 'Recipient Name');
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>
另外,上述文件的目录结构如下:
wwwroot
|___App_Data
|___jobs
|___triggered
|___send-sales-report
|___send_sales_report.php
|___inc
|___class.EmailMessage.inc
|___emails
|___sales_report.php
|___E-Mail.php
当我使用Azure门户(手动并按计划)运行PHP WebJob时,它以退出代码255失败; 但是,当我在Azure上使用Kudu控制台执行脚本时,效果很好。 此外,我还本地复制了运行环境,并且运行良好。
任何帮助深表感谢。
我建议您为您的应用启用PHP错误日志。 创建一个.user.ini
文件,并添加以下内容:
log_errors = on
请参阅此博客文章: 启用PHP错误日志记录
PHP错误日志的默认位置为: D:\\home\\LogFiles\\php_errors.log
这应该有助于进一步进行。
255
是错误。 请参阅PHP退出状态255:这是什么意思? 。 因此,您可能在PHP脚本中遇到致命错误。
通过使用register_shutdown_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(), 'name@emailprovider.com', 'Recipient Name');
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
function shutdown_function()
{
$e = error_get_last();
print_r($e);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.