Create Windows Service To Schedule PHP Script Execution
Create Windows Service To Schedule PHP Script Execution
Service to Schedule
PHP Script execution
If you want to schedule your PHP script or
any other command on Windows
Platform recursively after a fix interval of
time then you can create a Windows
Service for it. Windows service is very
easy to create in Visual Studio.Net. I’m
using C# language for this scheduler
service you can also use VB.net for it.
Basically we need this type of service if
we want to execute some PHP script in
background in a specific interval of time.
For example, If you want to import data in
bulk from some web service.
using System;
using
System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
namespace MyNewService
{
public partial class
MyNewService : ServiceBase
{
private Timer syncTimer
= null;
public MyNewService()
{
InitializeComponent
();
}
private void
syncTimer_Tick(object sender,
EventArgs e)
{
System.Diagnostics.
Process.Start(@"C:\xampp\htdocs
\task.bat");
}
}
}
The task.bat file is a batch file. We are
executing our PHP script through this
batch file. First we set the path of
directory where php.exe is located in your
windows. The import.php is basically
importing data in bulk from some web
and we need to execute this script file
background in every 3 minutes.
@echo off
cd\
set path=C:\xampp\php;
cd "C:\xampp\htdocs"
php import.php
exit