Setting Up Automatic Ticket Fetching on Windows Server
This guide will walk you through setting up a scheduled task in Windows Server to automatically run a PHP script that fetches tickets from your ticketing system.
Steps
Open Task Scheduler
- Press Win + R to open the Run dialog.
- Type taskschd.msc and press Enter to open the Task Scheduler -or- simply click the windows button and search for "Task Scheduler"
Create a New Task
In Task Scheduler, click on Create Task in the right-hand Actions panel.
Name the task (e.g., MyTicketsTask) and provide a description if desired.
Configure Triggers
Go to the Triggers tab.
Click New to create a new trigger.
Set the trigger to Daily.
Specify the start date and time.
Check the box for Repeat task every and set it to 5 minutes.
Ensure the Enable box is checked.
Click OK to save the trigger.
Configure Actions
Go to the Actions tab.
Click New to create a new action.
Set Action to Start a program.
In the Program/script field, browse to the path of php-cli.exe. Typically, this is located at C:\php\php.exe or similar.
In the Add arguments (optional) field, enter the path to your PHP script. For example: C:\yourtickets_website\api\cron.php.
Click OK to save the action.
Check Other Settings (Optional)
Conditions: Adjust any conditions that are necessary for your environment (e.g., only run when on AC power).
Settings: Review and adjust settings like Allow task to be run on demand and If the task fails, restart every if needed.
Confirm Cron Job Settings
Log in to your ticketing system's Admin Panel.
Navigate to Email > Settings.
Go to Autofetch and ensure that the cron job is deactivated if you're running the script manually through Task Scheduler.
Important Notes
Ensure the cron job is not active in the ticketing system’s settings to avoid conflicts with the Windows scheduled task.
Permissions: Ensure that the user account running the scheduled task has appropriate permissions to access the PHP executable and the script file.
By following these steps, you will have set up an automated task to regularly run your PHP script and fetch tickets from your ticketing system