Reputation: 461
I have developed a PHP Script which generates a simple financial report and sends it via SMTP (using the PHPMailer library).
I am attempting to host and execute the script using Azure Web Jobs, but unfortunately the job is failing each time I run it.
The WebJob is located at wwwroot\App_Data\jobs\triggered\send-sales-report\send_sales_report.php
on Azure.
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(), '[email protected]', '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; however, when I execute the script using the Kudu Console on Azure it works just fine. In addition, I have also replicated the running environment locally and it is working fine.
Any help is much appreciated.
Upvotes: 0
Views: 693
Reputation: 9950
255
is an error. See PHP exit status 255: what does it mean?. So, You may encounter a Fatal error in your PHP script.
It is possible to catch Fatal Errors by using register_shutdown_function
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(), '[email protected]', 'Recipient Name');
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
function shutdown_function()
{
$e = error_get_last();
print_r($e);
}
Upvotes: 1
Reputation: 2467
I would recommend you to enable PHP Error Logs for your app. Create a .user.ini
file and add the following to it:
log_errors = on
Refer this blogpost: Enable PHP error logging
The default location for the PHP Error logs will be: D:\home\LogFiles\php_errors.log
This should help in proceeding further.
Upvotes: 1