I just wondered if anyone had managed to get the contents of a remote URL asynchronously, work on it and then output it to the current document without using AJAX.
3条回答 默认 最新
- dqzpt40064 2013-05-17 12:53关注
Not with file_get_contents, no. Alternatively you can use the CURL extension and their non-blocking IO capabilities. All of this is available via the Multi Handlers of CURL. It's 'async' in the sense that you may poll the result and continue processing on other things if the result isn't ready to be read. This makes it 'async' in the sense that you're never blocking and waiting for the response, as long as there's work to be done - do it.. What's hard to understand for some people is the difference between async and non-blocking, in most cases with PHP what you really want is some sort of NB I/O. Given a few abstraction layers you can really come up with a nice IO callback interface with all the fun of anon functions, but thats another story..
See http://www.php.net/manual/en/function.curl-multi-init.php this is where it starts, the example included is great See http://www.php.net/manual/en/function.curl-multi-exec.php See http://www.php.net/manual/en/function.curl-multi-select.php for the NB poller
This guy avoids the ease of curl and goes straight to handling the http protocol which is yet another solution https://segment.io/blog/how-to-make-async-requests-in-php/ but requires a bit more of knowledge of the socket api.
Cheers
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 乌班图ip地址配置及远程SSH
- ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
- ¥15 PSPICE制作一个加法器
- ¥15 javaweb项目无法正常跳转
- ¥15 VMBox虚拟机无法访问
- ¥15 skd显示找不到头文件
- ¥15 机器视觉中图片中长度与真实长度的关系
- ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
- ¥15 java 的protected权限 ,问题在注释里
- ¥15 这个是哪里有问题啊?