dongqing4774 2015-02-10 13:11
浏览 90
已采纳

PHP中的异步方法调用

I have the following dilemma, I have a SOAP API, need to optimise a method:

public function myMethodForOptimisation(array $options) {
    //doing some stuff

    $this->requestsAnUltraSlowTimeConsumingMethod();

    return $someData;
}

I do not really need to wait for the finalisation of the $this->requestsAnUltraSlowTimeConsumingMethod() i just asynchronously want to say to this method to do stuff and return the result to customer.

Need to transform it in something like:

public function myMethodForOptimisation(array $options) {
    //doing some stuff

    async_method_call($this->requestsAnUltraSlowTimeConsumingMethod());

    return $someData;
}

Is there an async_method_call() in PHP ?

  • 写回答

2条回答 默认 最新

  • douba6361 2015-02-10 13:25
    关注

    You cannot execute a method asynchronously. But you could return the data to the client, close the connection, and execute your time consuming method once you disconnected.

    This answer goes in details.

    Another solution to execute php code asynchronously is forking a new process with pclose(popen()).

    Or for a really advanced solution you could look into the threading module of PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测