0

I want to execute a PHP function in every 5mins. A basic timer should do the trick. But how?

Example: I want to show something every 5mins in the screen (web page) using PHP and ajax or just PHP alone.

1
  • 1
    You need to use JS. It is not possible with just PHP, except in case of cron jobs. Commented Mar 28, 2011 at 11:02

4 Answers 4

2

In your case use javascript or meta timer - it will do the trick

Javascript

  setTimeout( 'yourAjaxFunction()', 3000 );
Sign up to request clarification or add additional context in comments.

1 Comment

OP wants to ` execute a PHP function in every 5mins.`. How do you intent to run a php code with javascript function?
1

You need to use server-side Crontab utility if you don't want to execute it yourself all the time from the browser. So you either have to find this option somewhere in shared hosting panel settings, or manually set it up on server if you own it. You can either call it through PHP's command line mode, or use curl on wget to fetch via http. You also can set up how often you can call it.

For example command can look like

* * * * */5 /usr/local/bin/wget -q -O /dev/null http://example.com/auto.php

Comments

0

Use a javascript timer that will refresh every 5 minutes(or will send a ajax request). You cannot use PHP on the client side, use javascript.

Comments

0

You can do it with jQuery, i made a simple function to do this:

function Timer()
{
    var timeout = 30000;
    setTimeout(function() {
        $.ajax({
            url: "urltofile",
            type: "POST",
            success: function(response)
            {
                [....] // do stuff with the response
                Timer(); // set new instance for timer after the response
            }
        });
    }, timeout);
}
//
Timer();

And in a PHP file you can load stuf you want to show

2 Comments

Just to clarify for you, 6000*5 is 5 x 1minute, not '5 times a minute', which suggests 5 times in one minute.
fair enough.. i ment the same

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.