curl在php中的使用
来源:互联网 发布:mac设置桌面应用 编辑:程序博客网 时间:2024/05/16 12:05
随着版本的不同curl在php中试用也变得有所不同,对于curl的资料,大家也是迷惑,确实关于curl,在网上还是能找到一些用法的,但是没有什么解释,今天,我就把自己所找到的资料 跟大家分享一下
首先是一些函数
curlm_multi_init
This function returns a CURLM handle to be used as input to all the other multi-functions, sometimes referred to as a multi handle in some places in the documentation. This init call MUST have a corresponding call to curl_multi_cleanup when the operation is complete.
这一个函数返回一个CURLM句柄,该句柄将会被用作其他所有的multi-函数的输入使用,也就是作为参数传递,这个初始化的call必须有一个相对应的函数调用curl_multi_cleanup,在操作完成的时候.
curl_multi_exec
该函数实际上调用了curl的底层的curl_multi_perform函数,我们来看一下,文档对他的描述
最为简单的描述是这样的;
reads/writes available data from each easy handle
翻译成中文就是;从每一个句柄中读或者写可获得数据
下面有一段话
This function handles transfers on all the added handles that need attention in an non-blocking fashion.
When an application has found out there's data available for the multi_handle or a timeout has elapsed, the application should call this function to read/write whatever there is to read or write right now etc.curl_multi_perform returns as soon as the reads/writes are done. This function does not require that there actually is any data available for reading or that data can be written, it can be called just in case. It will write the number of handles that still transfer data in the second argument's integer-pointer.
If the amount of running_handles is changed from the previous call (or is less than the amount of easy handles you've added to the multi handle), you know that there is one or more transfers less "running". You can then call curl_multi_info_read to get information about each individual completed transfer, and that returned info includes CURLcode and more. If an added handle fails very quickly, it may never be counted as a running_handle.
When running_handles is set to zero (0) on the return of this function, there is no longer any transfers in progress.
我们来看这段话到底说了什么:
这个函数处理所有的被添加的句柄上的数据传输,在一个引用程序发现有数据需要处理的时候或者超时发生了,应用程序应该调用这个函数,该函数在读或者写,完毕的时候返回,这个函数不要求,真的存在着数据需要读取或者写入,他可以在任何情况下被调用,调用玩这个函数之后,他将会设置传递给它的第二个参数(running -handles),该参数指示还有多少个活动连接
如果running-handles从前一次的调用中被调用了,那说明该传输已经完成了,或者出现了传输错误,为了查看每一个连接的传输情况,你需要调用curl-multi-read-info函数,他会返回一个包含一个三个数据的数组,具体请看php帮助文档。
当running-handles被curl设置为0的时候,那么这意味着已经完成所有的传输了。
你可能很迷惑它的返回值到底是什么,是不是??
CURLMcode type, general libcurl multi interface error code.
Before version 7.20.0: If you receive CURLM_CALL_MULTI_PERFORM, this basically means that you should call curl_multi_perform again, before you select() on more actions. You don't have to do it immediately, but the return code means that libcurl may have more data available to return or that there may be more data to send off before it is "satisfied". Do note that curl_multi_perform will returnCURLM_CALL_MULTI_PERFORM only when it wants to be called again immediately. When things are fine and there is nothing immediate it wants done, it'll return CURLM_OK and you need to wait for "action" and then call this function again.
This function only returns errors etc regarding the whole multi stack. Problems still might have occurred on individual transfers even when this function returns CURLM_OK. Use curl_multi_info_read to figure out how individual transfers did.
在7.20.0版本之前,如果你收到CURLM_CALL_MULTI_PERFORM,那么意味着,你应该再次调用curl_multi_perform函数,在你调用curl_multi_select之前,在没有他要处理的数据的时候,他会返回CURLM_OK,你只需要等待动作(暂时理解action为动作吧,因为我实在找不到比较好的词了),如果CURLM_OK被返回,那么你只需要等待,直到(注意了),这里是我们调用的curl_multi_select,他只返回值为-1,不管怎么样,他不会等待什么动作,只是在usleep这段时间之后,curl-multi-perform还是会被调用,可能会没有什么意义,但没办法curl_multi_select
FALSE
。curl_multi_getcontent($res)
CURLOPT_RETURNTRANSFER
,则返回获取的输出的文本流- curl在php中的使用
- 在php中使用curl
- 【php中的curl】php中curl的使用
- 【php中的curl】php中curl的使用
- 【php中的curl】php中curl的使用
- curl 命令在php中使用
- [CURL] -- PHP使用CURL详解
- PHP中的CURL函数库
- PHP中的CURL函数库
- php 中的 curl 函数
- PHP中的CURL
- php中的curl简述
- PHP中的cURL
- PHP中的数据传输CURL
- PHP中的cURL函数
- PHP中的数据传输CURL
- PHP中的curl函数
- PHP中的CURL详解
- 于惠普学习有感
- JAVA中经典同步问题
- thinkphp框架之关于网站语言包的设置和使用(多语言支持)
- HDU 1394 Minimum Inversion Number (线段树 or BIT)
- 数据结构与算法分析(c++版) #5 可利用空间表提高链表效率
- curl在php中的使用
- 调用系统拍照、录像、录音功能并播放的demo
- 面试题用两个栈构造一个队列和用两个队列构造一个栈
- php脚本的一些注意事项
- 滚动跑马灯问题
- MySQL GUI Tools 使用简介
- C++那些细节--inline关键字
- Linux分区
- 验证vector swap内存释放