Create Windows
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 [Link]. I’m
using C# language for this scheduler
service you can also use [Link] 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.
You need to follow these steps: -
• Create a project by using the
Windows Service application template.
This template creates a class for you that
inherits from ServiceBase and writes
much of the basic service code, such as
the code to start the service.
• Write the code for the OnStart
and OnStop procedures, and override any
other methods that you want to redefine.
• Add the necessary installers for
your service application. By default, a
class that contains two or more installers
is added to your application when you
click the Add Installer link: one to install
the process, and one for each associated
service that your project contains.
• Build your project.
• Create a setup project to install
your service, and then install it.
• Access the Windows 2000
Services Control Manager and start your
service.
For more detail check “Walkthrough:
Creating a Windows Service
Application in the Component
Designer” topic in MSDN.
using System;
using
[Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace MyNewService
{
public partial class
MyNewService : ServiceBase
{
private Timer syncTimer
= null;
public MyNewService()
{
InitializeComponent
();
}
protected override void
OnStart(string[] args)
{
syncTimer = new
Timer();
[Link]
rval = 180000;
[Link]
sed += new
[Link]
er(this.syncTimer_Tick);
[Link] =
true;
}
protected override void
OnStop()
{
[Link] =
false;
}
private void
syncTimer_Tick(object sender,
EventArgs e)
{
[Link].
[Link](@"C:\xampp\htdocs
\[Link]");
}
}
}
The [Link] file is a batch file. We are
executing our PHP script through this
batch file. First we set the path of
directory where [Link] is located in your
windows. The [Link] 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 [Link]
exit