I run apache and php on a windows xp machine. I want to run a php script at regular intervals to backup a MySql database. The backup script I have already written and know it works fine. My question is how do I go about running a php script with windows task scheduler. I’ve never used windows task scheduler before so as much explaination as possible would be a big help. Thanks for reading this and hope someone can help me sort this.
Cheers for that. So i’ve set up a scheduled task to run the following
C:\PHP\php.exe c:\Program Files\Apache Group\Apache\htdocs\db_backup\db_backup.php
But nothing happens apart from the php command box comes up for a split second and closes without executing my db_backup.php script. Script works fine when called from browser. Have I passed the file path parimeters correctly to php.exe as above? db_backup.php calls on several includes - is this ok when running script through php.exe.
Thanks again.
Appologise for bumping this but I am still struggling to get my database backup script working from scheduled tasks and really could do with some help/advice. Thanks again.
Try copying the script to a simpler directory, like C:\scripts, and point the task scheduler to the new script location. You might also want to try encapsulating the cli string in quotes, as well.
If you have error logging enabled in PHP, you might want to check there, to see if you can determine the problems, too.
Cheers Dave you’re a star. Simply moving my backup scrips to c:/phpbackup did the trick. Here’s me thinking an absolute file path was just that regardless of how long it may be. Great thing this windows xp
Perhaps it needs the path in 8.3 format?
i.e.
C:\PHP\php.exe c:\Progra~1\Apache~1\Apache\htdocs\db_backup\db_backup.php
Click Start->Run and type ‘command’ and hit enter. This should bring up a dos prompt that doesn’t support long file names (as opposed to running ‘cmd’ which does). Then type “dir /x” (/x makes it display the shortnames as part of the dir dump)…
Using “dir /x” and “cd” you can walk up to where the script is located in the Apache directory and see what the full path would be using 8.3 format.
Perhaps give it a try and see if that was the reason Scheduler was giving you issues?
Cheers,
Keith.
Actually, Keith, with XP it’s “CMD”, rather than “command”, but other than that, you’ve got some good advice. Just wanted to make things clear…
both work actually.
command.com = windows DOS
cmd.exe = “DOS” XP Version
OOPS! My bad. I’d never tried to use “command”, since all the paperwork I’d read pointed to “CMD”. Live and learn, I guess…
and where I have to write the time?
http://www.sitepointforums.com/showthread.php?threadid=135975
Regards from Spain.
Like to thank Dave, astericks & Taoism for your help. Tried the path in the 8.3 format but still no joy. I’m happy to have it running from c:/ though as it’s more secure being away from my web directory.
Marylin77, if your running php, apache etc from your own pc then I would say setting up a windows scheduled task is better than the script you mention in your http://www.sitepointforums.com/show…threadid=135975 post.
Don’t like the idea of tasks such as sending e-mails, backups etc only being triggered when you get a page hit. You can set windows schedular up monthly and even select the months if you only want something happening every 3 months. As your php script is also in c:/ then you just need to enter the same as what the folks above adviced me i:e C:\PHP\php.exe c:/scripts/mail2.php
Thanks again to the above named who helped me sort this. Much Appreciated.
help me, too! :[
What I am doing wrong?
Intrim wrote:
Marylin77, if your running php, apache etc from your own pc then I would say setting up a windows scheduled task is better than the script you mention in your http://www.sitepointforums.com/show...threadid=135975 post.
And I write:
yes,I am running php ,apache ect from my own pc…
what do i have to do to set up a windows scheduled?Have I to configure any file?where i have to write the time I want?
Thanks in advance.
Did you need to know how to set up the task, now that the script is working? I don’t fully understand where you need help. (I’m probably over thinking this)
Yup! Over thinking things… Go figure!
Ok. To set up a scheduled task, you need to go into your control panel (these instructions assume Windows XP), and click on “Scheduled Tasks” (funny thing, that. ) there will be an icon labeled “Add Scheduled Task” (or the spanish translation, perhaps?). Click on that, and follow the instructions within the wizard that pops up. The instructions are relatively clear, but if you have troubles, post back, and we’ll see what we can do.
And yes folks, I know that this is no longer the correct forum for this, and that the thread has been “hijacked”. It happens, and I’m more interested in helping out than strictly following conventions. I happen, too…
On windows xp it’s
control panel
scheduled tasks
add scheduled task
this will bring up a wizard
assuming you have php set up as default browse to c:\PHP\php.exe
set a name for the task and select how often you want it to run
select time of day you want task to run and if you selected monthly select which months you want.
Enter username and password (this will be username and password you log on pc as) i had no password set so had to set a windows login password as schedular won’t work with no password set.
click finish
you then need to select the task and add c:\scripts\mail2.php after c:\PHP\php.exe in the run text area
it will ask for username and password again after this change. If there are quotes round C:\PHP\php.exe c:\scripts\mail2.php then remove them as for some reason it doesn’t want them.
When this is done you can test everything is ok by right clicking the task and selecting run.
The above is for windows xp - not sure if it’s the same for 98 or me but i’d imagine it’s similar.
Hope this helps.
The location of the Scheduled Tasks “folder” is slightly different, but that’s about it.
thanks…i have followed all the steps (I have installed php.exe in c:/Archivos de programa/Easyphp/php/php.exe).
In the pop up wizard I examine mail2.php
I have programmed the mail2.php daily and when the time comes…Macromedia Dreamweaver is openned with my mail2.php XDD…lol…
why?:[[[
In spanish is:Panel de control->Tareas programadas->Agregar tareas programadas :]
Thanks in advance.
what is the location of mail2.php? (I mean the entire path)
mail2.php is in:
C:/Archivos de programa/Easyphp/www/miphp/mail2.php
in fact…my configuration is:
Ejecutar (Execute) “c:/Archivos de programa/Easyphp/www/miphp/mail2.php”
Iniciar en: (Start in) “C:/Archivos de programa/Easyphp/php/php.exe”
Comentarios (Comments): empty.
What is wrong? :[
I use w me.
PD:
well…i removed the double quotes and in Ejecutar I put the second folder (copy)…I mean c:/scripts/mail2.php…and again Dreamweaver is openned…[
On the other hand: somebody wrote:
i had no password set so had to set a windows login password as schedular won’t work with no password set.
///mmm…i have not any password…It will be the reason?