[英]PHP Azure WebJob - Failing With Exit Code 255 (But Working Fine On Kudu)
I have developed a PHP Script which generates a simple financial report and sends it via SMTP (using the PHPMailer library). 我已经开发了一个PHP脚本,该脚本可以生成简单的财务报告,并通过SMTP(使用PHPMailer库)发送报告。
I am attempting to host and execute the script using Azure Web Jobs, but unfortunately the job is failing each time I run it. 我正在尝试使用Azure Web Jobs托管和执行脚本,但是不幸的是,每次运行该作业都会失败。
The WebJob is located at wwwroot\\App_Data\\jobs\\triggered\\send-sales-report\\send_sales_report.php
on Azure. WebJob位于Azure上的
wwwroot\\App_Data\\jobs\\triggered\\send-sales-report\\send_sales_report.php
中。
The contents of the script are as follows; 该脚本的内容如下: as can be seen, the script imports a number of other scripts:
可以看出,该脚本导入了许多其他脚本:
<?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";
}
?>
In addition, the directory structure of the files mentioned above is as follows: 另外,上述文件的目录结构如下:
wwwroot
|___App_Data
|___jobs
|___triggered
|___send-sales-report
|___send_sales_report.php
|___inc
|___class.EmailMessage.inc
|___emails
|___sales_report.php
|___E-Mail.php
When I run the PHP WebJob using the Azure Portal (both manually and on a schedule), it fails with exit code 255; 当我使用Azure门户(手动并按计划)运行PHP WebJob时,它以退出代码255失败; however, when I execute the script using the Kudu Console on Azure it works just fine.
但是,当我在Azure上使用Kudu控制台执行脚本时,效果很好。 In addition, I have also replicated the running environment locally and it is working fine.
此外,我还本地复制了运行环境,并且运行良好。
Any help is much appreciated. 任何帮助深表感谢。
I would recommend you to enable PHP Error Logs for your app. 我建议您为您的应用启用PHP错误日志。 Create a
.user.ini
file and add the following to it: 创建一个
.user.ini
文件,并添加以下内容:
log_errors = on
Refer this blogpost: Enable PHP error logging 请参阅此博客文章: 启用PHP错误日志记录
The default location for the PHP Error logs will be: D:\\home\\LogFiles\\php_errors.log
PHP错误日志的默认位置为:
D:\\home\\LogFiles\\php_errors.log
This should help in proceeding further. 这应该有助于进一步进行。
255
is an error. 255
是错误。 See PHP exit status 255: what does it mean? 请参阅PHP退出状态255:这是什么意思? .
。 So, You may encounter a Fatal error in your PHP script.
因此,您可能在PHP脚本中遇到致命错误。
It is possible to catch Fatal Errors by using register_shutdown_function
function . 通过使用
register_shutdown_function
函数可以捕获致命错误。 The following code sample you can use to log the Fatal error when it occurred. 以下代码示例可用于在发生致命错误时记录该错误。
<?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.