如何连续运行PHP和/或CodeIgniter函数

I am working on the location-based social networking website where I am integrating the foursquare. I have used login with the foursquare, whenever the user login with his foursquare account I get his access token by using this I get his all data from the foursquare account which is very large and takes lot of time. That's why I am looking for a solution which will retrieve the foursquare data continuously in cycle.

Is there any way to run the codeIgniter or PHP function continuously to update the all users data instead of updating the data scheduled basic like using cronjob, it should run like once I run the function it will run infinite time without stop.

Note:

I am using CURL to get the data from the foursquare

Thanks in advance!

What you need is to daemonize PHP process, I've done this in past, and honestly can not remember what I've used, but quick google search gave me http://pear.php.net/package/System_Daemon .

What I can tell you is that PHP is not a good choice for this kind of things. I've had a huge amount of issues, that were directly related to the fact that PHP process was working all the time. Eventually, I rewrote that to Java (and http://commons.apache.org/proper/commons-daemon/jsvc.html)

You can also take a look at job servers, for example Gearman (http://gearman.org/) is well known. Here is Gearman PHP lib http://php.net/manual/en/book.gearman.php .

I personally have used http://www.celeryproject.org/ for these kind of tasks (since the tasks can be scheduled, and manually triggered).

You can write a simple PHP script like following and run this script by scheduling it in a cron job and then once this script runs, delete the cron tab (the script will keep runing):

while (true)
{
    // Setup your CURL request for foursquare
    // Fire the CURL request and get the results
    // do the processing
    // You can probably put a sleep here before it again   loops
    // Here is the magic to break the infinite loop - check a
    // variable from database table or from some ini file and break the loop
    // if the variable is set
}

Hope it helps.