Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: How to create a batch file for a php script

1. ## How to create a batch file for a php script

Hi everyone ,

I need to schedule a php script to run daily at night 11:59 pm .
So i need to create a batch file for php script to schedule with the windows scheduler .
I am not getting how create a batch file for a php script .

Please tell me the code to create the batch file for php script . suppose my script name is post_mail.php .

Thank,
Rajesh.

• Originally Posted by Rajesh77
Hi everyone ,

I need to schedule a php script to run daily at night 11:59 pm .
So i need to create a batch file for php script to schedule with the windows scheduler .
I am not getting how create a batch file for a php script .

Please tell me the code to create the batch file for php script . suppose my script name is post_mail.php .

Thank,
Rajesh.
It's a Windows server (which I don't have direct experience with) but I believe you just create a batch (*.bat) file as you would for a regular Windows PC.

There are some details here if you want to build it manually:
http://technet.microsoft.com/en-us/l...8WS.10%29.aspx

And an example for some CMS program, but the basic steps should be the same:

• Assuming you have internet explorer running, you can call a vbs script from a batch file to open the php page through IE. For example:

This is inside foo.vbs (notice the location of your script):

Code:
Dim objIEA
Set objIEA = CreateObject("InternetExplorer.Application")
objIEA.Navigate "http://localhost/post_mail.php"
While objIEA.Busy
Wend
Set objIEA = Nothing
then call foo.vbs from a batch file.

this is inside bar.bat:
Code:
wscript.exe "C:\foo.vbs"
The internet explorer window should be invisible. If you want the batch file to be invisible too, you can mask it with this invis.vbs script:

inside invis.vbs:
Code:
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
and from a launch.bat you can load the entire visible sequence:

inside launch.bat:
Code:
wscript.exe "C:\invis.vbs" "C:\bar.bat"
Now all you need to do is go to scheduled tasks and schedule launch.bat to run at whatever interval you want. Make sure all the file locations are correct.

EDIT: Test out loading your script from a normal internet explorer window first. Make sure all security settings in IE allow you to load the script. When I tried it, a plug in interfered and I had to disable it before it worked.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•