Hello together...

hope someone can help me:-)

I want to to run a php file every ten seconds on serverside,
how can I do this?

CronJobs are not really working; Server = Apache, PHP 4 or 5.

Greetings & Thanks

Recommended Answers

All 13 Replies

Why do you need a script to run every 10 seconds? There has to be a more efficient way to do whatever it is you are trying to do.

Cron jobs are your easiest solution.
Another method would be making 2 PHP scripts to bounce off of each other.

File 1: Run the target script wait 10 seconds and call File 2.

File 2: Run target scritpt wait 10 seconds call File 1.

It would be advisable to make a script take in a $_GET value to 'exit' the scripts.

So once you go to file 1: in your browser, it will create a continuous loop which will bounce form one file to the next. Until you type in this exit command.

Hi...

thanks for your responses. Well, I need it because I must update
database entries and perform new calculations every ten seconds.

File 1: Run the target script wait 10 seconds and call File 2.
File 2: Run target scritpt wait 10 seconds call File 1.

Seems a good idea, but note the call must be don on the server.
I'll try it:-) As I know, CronJob's can't be executed regulary each
ten second or may be my Information false?

Greetings

Or you can simply ad

header('refresh:10; url=same_page.php');

Hi...

Thanks, good idea, can I use a timevalue, like refresh 12:00:xx ?

Greetings

Or you can simply ad

header('refresh:10; url=same_page.php');

Once this is setup and we go to the script URL.
this header() function will active.

Will i run in a continuous loop forever? or only if the script is being viewed by a user.

Secondly, if this is running in a continuous loop.
how can we stop the execution ?

Drag...

Ir runs only when viewed by a user and will run in continuous loop until the user closes the browser.

Of course, you can setup a $_GET variable to count the loops and stop at some point

Thanks, good idea, can I use a timevalue, like refresh 12:00:xx

As far as I know, in header(refresh...) you can only specify the number of seconds the script has to wait untill refresh, not a certain hour.

Thanks :icon_wink:

You're welcome :)

Right. cool.
So, my method would work continuously,
without someone viewing the page.

Yours would only work if someone had the script open.

So it's up to you maninweb. Either will work, it just depends on how you want to do it.

Hi...

well I will try out all ideas. Logically it must be possible to open
a browser on the server (Linux) and run the script all ten seconds
or just once on specified time. As I'm writing now the first call of
the script can be done by a cronjob. Hope I'm right. :icon_smile:

Greetings

I am using a script for banner rotation that I want to refresh every 10 seconds. I used this

header('refresh:10; url=filename.php');

in the file but in the first interval the browser leaves the website and shows just the refreshing banners in a page. How can I refresh and remain in the site?

Thank you

Actually I got it done with a frame. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.