Run PHP WebJobs on App Service Linux.
WebJobs Intro
WebJobs is a feature of Azure App Service that enables you to run a program or script in the same instance as a web app. All app service plans support WebJobs. There's no extra cost to use WebJobs. This sample uses a Triggered (scheduled) WebJob to output the system time once every 15 minutes.
Create Web App
Before creating our WebJobs, we need to create an App Service webapp. If you already have an App Service Web App, skip to the next step Otherwise, in the portal, select App Services > Create > Web App. After following the create instructions and the PHP 8.4 runtime stack, create your App Service Web App. The stack must be PHP, since we plan on writing our WebJob using PHP and a bash startup script. For this example, we’ll use PHP 8.4.
Next, we’ll add a basic WebJob to our app.
Create WebJob
Before we do anything else, let’s write our WebJob. This will execute every time our WebJob is triggered. WebJobs on App Service can be run on a Triggered (Scheduled) basis or Continuously. This example uses a Triggered WebJob.
For this example, we’ll need to compress two files into a zip archive that we’ll upload to our App Service Web App. We’ll need a startup script and a PHP file.
The full code for this sample is available at: Azure-Samples/App-Service-PHP-WebJobs-QuickStart
Digging into the code, our PHP file located in webjob.php is relatively simple. It just outputs the current time to the console.
<?php
// Get the current time
$current_time = date("Y-m-d H:i:s");
// Display the current time
echo "The current time is: " . $current_time;
?>
The run.sh script is located at the root of our git repo. This script will run when our WebJob is triggered, and it is the job of this script to kick off our PHP file.
#!/bin/bash
php -f webjob.php
Now we have everything we need to assemble our zip file. Again, there are multiple ways to do this, but for this demo we’ll use the zip CLI utility to create our zip file called webjob.zip. Run the following command to create the zip.
zip webjob.zip run.sh webjob.php
Now it’s time to create our WebJob and upload our zip file.
Create WebJob in Portal
Start by entering your Web App overview page. Then, under Settings select WebJobs. Here we can create and manage our App Service WebJobs for this Web App. Click Add to create a new WebJob.
Now we can name our WebJob, upload our zip from the previous step, and choose our execution type. Under Type, select Triggered. Under CRON Expression, enter the following to trigger our WebJob once every 15 minutes.
0 */15 * * * *
Note: These are NCRONTAB expressions, not standard Linux CRONTAB expressions. An important distinction.
Now click Create WebJob to finish making our new WebJob. Let’s test it out now.
Run Manually or Scheduled
To manually test our WebJob, we can click the play button under Run. A status of Completed means that WebJob is finished.
Confirm Results in Logs
We can check the logs to confirm that the console print statements from our PHP file were output to the console. There may be some warnings at startup, but these are typically safe to ignore for PHP WebJobs.
While this is a basic example, WebJobs are a powerful and easy to use feature that have incredible utility for running scheduled (or continuous) actions in conjunction with your App Service Web Apps at no additional cost.
Learn more about WebJobs on App Service
Published Apr 08, 2025
Version 1.0denverbrittain
Microsoft
Joined June 23, 2022
Apps on Azure Blog
Follow this blog board to get notified when there's new activity