【问题标题】:How to run the PHP and/or CodeIgniter function continuously如何连续运行 PHP 和/或 CodeIgniter 函数
【发布时间】:2013-08-07 13:23:59
【问题描述】:

我正在开发基于位置的社交网络网站,我正在整合foursquare。我已经使用foursquare登录,每当用户使用他的foursquare帐户登录时,我都会使用它获取他的访问令牌,我会从foursquare帐户中获取他的所有数据,这个帐户非常大并且需要很多时间。这就是为什么我正在寻找一种可以循环连续检索四方数据的解决方案。

有什么方法可以run the codeIgniter or PHP function continuously 更新所有用户数据instead of updating the data scheduled basic like using cronjob,它应该像我运行该函数一样运行,它将无限次运行而不会停止。

注意:

我正在使用CURL从foursquare获取数据

提前致谢!

【问题讨论】:

    标签: php mysql curl codeigniter-2 foursquare


    【解决方案1】:

    您可以编写一个简单的 PHP 脚本,如下所示,并通过将其安排在 cron 作业中来运行此脚本,然后在此脚本运行后,删除 cron 选项卡(脚本将继续运行):

    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
    }
    

    希望对你有帮助。

    【讨论】:

      【解决方案2】:

      你需要的是守护 PHP 进程,我过去做过,老实说不记得我用过什么,但快速谷歌搜索给了我 http://pear.php.net/package/System_Daemon

      我可以告诉你的是,PHP 不是这类事情的好选择。我遇到了很多问题,这些问题与 PHP 进程一直在工作这一事实直接相关。最终,我将其重写为 Java(和 http://commons.apache.org/proper/commons-daemon/jsvc.html

      您还可以查看作业服务器,例如 Gearman (http://gearman.org/) 是众所周知的。这是 Gearman PHP 库 http://php.net/manual/en/book.gearman.php

      我个人使用http://www.celeryproject.org/ 来处理这类任务(因为这些任务可以安排,也可以手动触发)。

      【讨论】:

        猜你喜欢
        • 2017-05-18
        • 1970-01-01
        • 1970-01-01
        • 2020-09-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-02
        相关资源
        最近更新 更多