在PHP中的异步函数调用 [英] Asynchronous Function Call in PHP

查看:116
本文介绍了在PHP中的异步函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个PHP的Web应用程序,我需要在要求如根据用户的请求获取远程服务器中有人进行一些网络操作。

I am working on an a PHP web application and i need to perform some network operations in the request like fetching someone from remote server based on user's request.

是否有可能以模拟PHP异步行为因为我有一些数据传递给函数,并且还需要从它的输出。

Is it possible to simulate asynchronous behavior in PHP given that i have to pass some data to a function and also need output from it.

我的code是这样的:

My code is like:

<?php

     $data1 = processGETandPOST();
     $data2 = processGETandPOST();
     $data3 = processGETandPOST();

     $response1 = makeNetworkCall($data1);
     $response2 = makeNetworkCall($data2);
     $response3 = makeNetworkCall($data3);

     processNetworkResponse($response1);
     processNetworkResponse($response2);
     processNetworkResponse($response3);

     /*HTML and OTHER UI STUFF HERE*/

     exit;
?>

每个网络操作需要大约5秒钟即可完成总共15秒增加给我的应用程序的响应时间,我做3请求。

Each network operation takes around 5 seconds to complete adding a total of 15 seconds to the response time of my application given i make 3 requests.

该makeNetworkCall()函数只是做一个HTTP POST请求。

The makeNetworkCall() function just do a HTTP POST request.

远程服务器是一个第三方的API,所以我没有在那里任何控制。

The remote server is an 3rd party API so i don't have any control over there.

PS:请不要回答给出关于AJAX或其他东西的建议。目前我正在如果我能做到这一点通过PHP可能是用C ++的扩展或类似的东西。

PS: Please do not answer giving suggestions about AJAX or Other things. I am currently looking if i can do this through PHP may be with an C++ extension or something like that.

推荐答案

我认为这个问题的答案在这里奠定了:

I believe that answer lays here:

<一个href=\"http://stackoverflow.com/questions/13846192/php-threading-call-to-a-php-function-asynchronously\">PHP线程调用PHP函数异步

快速注:使用线程

这篇关于在PHP中的异步函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆