Mike Mike - 4 months ago 27
PHP Question

How to create a task on Windows to open a webpage and then close it?

I have a script written in PHP. my PHP server is running on a Windows Server.

How can I schedule a task that will open a web link "URL" and after the page finish executing close the browser.



As others have said, you use the Windows Task Scheduler which allows similar functionality to CRON but also a lot more (startup/down, events, etc.)

You can call Internet Explorer from a command with the url as a parameter:

iexplore.exe "http://etc.etc.etc"

You may need to explicitly add the path to iexplore.exe Of course, as you say, you would then need to kill the browser process afterwards.

Better would be to add a simpler command to a folder on your path such as CURL for Windows or WGET for Windows. Direct the output of the command to null, the command will exit with a testable return code should you need to further check whether it worked.

A third option would be to use PowerShell though I think that would be overkill in this case. I'd use it if I needed to test the return code for logging or to execute some other task on failure (e.g. write an error to the Windows Event Log and have a second task set up to run when that event occurs).

A 4th option would be to call PHP as this is supported if you have PHP installed on the server. Again though, the overheads of startup wouldn't make this worthwhile.

Personally, I would use WGET.