Hi, I have developed a SMS Application. There is a file name my.php I want to execute it after every 10 seconds so I can get new files which arrive. please guide me

You can run it through the task scheduler, but I think you can only specify per 5 minutes as smallest interval.

From where I can open task sheduler

Depends on the OS I think. With Win7 just type it, Vista and XP probably have them in accessoires or system tools.

If the page is only ever going to be accessed with localhost, you could just have the page open constantly and code it to refresh itself every 10 seconds.

its good suggestion to open a page but I want to learn how to do it using coding .

I think i have to use refresh option in my my.php file

You can create a deamon to run indefinitely, and have it invoke your file every few minutes.

Simple version:






It will need to be run from the command line. Example:

php deamon.php

How its possible?? is there any need of browser for this???

It is best to use the command line. However, you can use the browser.

If using the browser, two things to remember:
1) The webserver will timeout, or browser/client will timeout.
2) The page will have to stay open

To prevent the server from ending the PHP process you can use:



This allows the PHP script to execute indefinitely.

To prevent the browser from timing out, and also allow you to close the page you can send the Content-Length header from the browser. This has the effect of completing the page load in the browser.

ob_start(); // place at top of script

echo str_pad('', 256); // IE needs some content

// ............... put any messages or HTML here ...............

$content_length = ob_get_length(); // length of content
header('Content-Length: ' . $content_length); // set the length of content

ob_flush(); // flush output to browser

// now you can do what you want as the browser has already loaded

// ............ run your script here ................


As you can see, this is a bit hacky. If you run it in the command line, PHP automatically runs the script for ever and won't time out. You also don't need to send output for the browser, or trick the browser into completing the page load.