Setting Up A Cronjob In Windows Xampp

Setting Up A Cronjob In Windows Xampp

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Setting Up A Cronjob In Windows Xampp

Windows lacks a native cron daemon, so translating a standard Unix cron syntax like 0 * * * * directly into a Windows environment requires changing your approach entirely. The command you provided attempts to change directory and execute a PHP script every minute: 0 * * * * cd C:/xampp/htdocs/plugins/moviefeed/ && php cron.php. While this logic is sound, the implementation differs significantly between Linux servers and the XAMPP environment running on Windows.

To achieve this behavior on Windows, you need to leverage a task scheduler rather than a daemon process. The most robust native solution available in Windows is Task Scheduler. It allows you to define triggers (like every minute) and actions (running specific commands), handling persistence and error reporting better than simple batch scripts.

The first step involves creating the actual script that will be executed. In your XAMPP installation directory, create a new file named cron.bat (or .cmd) in the root of your project or within the C:/xampp/htdocs/plugins/moviefeed/ directory itself. Inside this file, you need to replicate the logic from your Unix cron expression. Since Windows batch files do not support the & & chaining syntax in the same way shell scripts do, you must use the && operator correctly.

Create a file named run_cron.bat and add the following content:

@echo off
cd /d "C:\xampp\htdocs\plugins\moviefeed"
if exist cron.php (
    php cron.php
) else (
    echo cron.php not found in current directory.
)

The cd /d command is crucial here. It ensures that the script changes both the drive letter and the directory path, which is necessary if you are running this from a different context or if the current working directory of the Task Scheduler task isn't the one you expect. The if exist check prevents PHP errors if the script file is temporarily missing, though in your specific case, you likely want to know immediately if cron.php is gone.

Next, configure the Windows Task Scheduler. Open the interface by searching for "Task Scheduler" in the Start menu. Click "Create Basic Task" or "Create Task" for more advanced options. In the "General" tab, give the task a descriptive name like "Moviefeed Cron". Under "Run whether user is logged on or not," check this box and enter an account with administrative privileges that has write access to your htdocs folder. This is often a point of failure; XAMPP typically runs under your local user context, so you must ensure the scheduled task uses an account capable of writing to C:\xampp\htdocs.

In the "Triggers" tab, click "New." Set the beginning to "On a schedule," select "Daily," and in the advanced settings for that trigger, choose "Repeat task every 1 minute for a duration of 'No end time'." This effectively replicates the 0 * * * * frequency. You must ensure the start time is set correctly if you aren't using the default midnight start.

Finally, in the "Actions" tab, click "New." Select "Start a program," browse to your newly created C:\xampp\htdocs\plugins\moviefeed\run_cron.bat, and leave the arguments field blank. Ensure the "Start in (optional)" field is set to C:\xampp\htdocs\plugins\moviefeed or left blank if the batch file handles the directory change internally as shown above.

A common pitfall when running PHP scripts via Task Scheduler on Windows involves how the command is invoked. If your run_cron.bat simply calls php cron.php, it relies on the PATH environment variable to find the XAMPP PHP executable. If the script fails silently, it might be because the scheduler is running with a different environment than when you manually open Command Prompt in the XAMPP folder. You can force the correct environment by specifying the full path to the PHP executable:

"C:\xampp\php\php.exe" cron.php

This approach eliminates PATH ambiguity. Additionally, consider enabling output logging. By default, Windows Task Scheduler does not capture stdout or stderr unless configured otherwise. To debug issues like database connection timeouts or missing dependencies in cron.php, you should redirect the output to a log file within the same directory:

"C:\xampp\php\php.exe" cron.php >> C:\xampp\htdocs\plugins\moviefeed\cron.log 2>&1

This appends both standard output and standard error to a text file, allowing you to review the execution history after a minute has passed without needing to open the Task Scheduler UI every time. This setup provides a reliable, native Windows alternative to Unix cron jobs while maintaining the flexibility required for local development environments like XAMPP.

Our network