【问题标题】:Is there any setTimeout equivalent in php? [duplicate]php中是否有任何等效的setTimeout? [复制]
【发布时间】:2013-10-04 16:17:01
【问题描述】:

php 中是否有与javascript setTimeout 等效的方法?

我知道 php 不是多线程,但我可能是错的。

【问题讨论】:

标签: php


【解决方案1】:

不,没有。主要是因为 PHP 是服务器端的,所以定时事件没有多大意义。不过,sleep 函数会在给定的时间内停止执行。

【讨论】:

    【解决方案2】:

    你可以用pthreads在PHP中做多线程

    来自 PHP 手册:

    pthreads  is an Object Orientated API that allows user-land multi-threading in PHP.
    It includes all the tools you need to create multi-threaded applications targeted at the Web or the Console.
    PHP applications can create, read, write, execute and synchronize with Threads, Workers and Stackables.
    

    参考文献

    1) http://www.reddit.com/r/PHP/comments/1jo517/multithreading_in_php_with_pthreads/

    2) https://github.com/krakjoe/pthreads

    【讨论】:

      【解决方案3】:

      PHP 有线程,因此您可以像使用其他多线程语言一样fork

      当然,您总是可以创建自己的事件循环;)

      【讨论】:

        【解决方案4】:

        您无法获得等效的 JS。与此无关。是不同的技术。

        我不知道要做什么。但是您可以为 php.ini 文件设置 max_execution_time 或在脚本级别覆盖该值。

        看看

        http://php.net/manual/en/function.set-time-limit.php

        【讨论】:

          猜你喜欢
          • 2012-05-28
          • 1970-01-01
          • 1970-01-01
          • 2015-12-06
          • 1970-01-01
          • 2021-04-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多