0

I am using a WAMP server.

Is it possible to run a script as long as WAMP server is on? If so, how? If it can't be done, can XAMPP do it or any other development server?

Edit: I want to run a PHP script then insert data in the database on specific dates and I am using Windows 7.

JohnSmith
  • 1,457
  • 2
  • 18
  • 27

5 Answers5

3

Based on comments:

You're looking at the problem wrong. Write a script and use a Cron job for it. If you're on a windows machine, scheduled tasks work too.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
2

I want to run a PHP script then insert data in the database on specific dates.

Use a cronjob. Most control panels offer them, else use crontab on linux or the task scheduler in Windows.

Devator
  • 3,686
  • 4
  • 33
  • 52
1

Try to write this kind of script:

<?php

while (true) {
    // Do something
}

And then launch it using the PHP CLI (command line) :

php your_script.php
adrien
  • 4,399
  • 26
  • 26
  • That would lock the PHP process and prevent all further requests. – Madara's Ghost May 04 '12 at 12:30
  • No it won't, it depends on what you put inside the `while` loop (think `sleep(1000);` for instance). A cron is not always enough, it depends on what JohnSmith wants to do. – adrien May 04 '12 at 12:33
1

It seems you are describing a daemon. If your scrpit breaks you need the functionality so it can handle errors and resume itself. Run php script as daemon process

Creating a daemon in PHP seems like it is an en devour but provides the functionality you desire.

Community
  • 1
  • 1
dm03514
  • 54,664
  • 18
  • 108
  • 145
1

Use Window's Task Scheduler / Manager (run taskschd.msc) to do this...

It's like cron but for Windows.

You can give it a URL to hit every so often (via executing cURL, wget, powershell, VBS, IE/Firefox/Chrome), or use it to directly execute a PHP script via php.exe.

For example, if I wanted to run a PHP file (via my Wamp-Developer), I would just add a task that executes this...

C:\WampDeveloper\Components\Php\php.exe -f "C:\my_php_file.php"

You can specifiy for it to also use / or not use the php.ini file (check php --help).

Or..

C:\WampDeveloper\Tools\curl\curl.exe http://localhost/my_php_file.php

You can HEAD, POST, login, etc with cURL... http://curl.haxx.se/docs/manual.html

Since you're using WampServer, you'd just update the Wamp-Developer paths above and it should work (I don't know where WampServer or Xampp places php or curl).

rightstuff
  • 6,412
  • 31
  • 20