首页 > 作文

PHP中CURL方法curl

更新时间:2023-04-06 10:48:49 阅读: 评论:0

php curl curl_topt 参数

bool curl_topt (int ch, string option, mixed value)
curl_topt()函数将为一个curl会话设置选项。option参数是你想要的设置,value是这个选项给定的值。

下列选项的值将被作为长整形使用(在option参数中指定):
curlopt_infilesize : 当你上传一个文件到远程站点,这个选项告诉php你上传文件的大小。
curlopt_verbo : 如果你想curl报告每一件意外的事情,设置这个选项为一个非零值。
curlopt_header : 如果你想把一个头包含在输出中,设置这个选项为一个非零值。
curlopt_noprogress: 如果你不会php为curl传输显示一个进程条,设置这个选项为一个非零值。注意:php自动设置这个选项为非零值,你应该仅仅为了调试的目的来改变这个选项。
curlopt_nobody : 如果你不想在输出中包含body部分,设置这个选项为一个非零值。
curlopt_failonerror : 如果你想让php在发生错误(http代码返回大于等于300)时,不显示,设置这个选项为一人非零值。默认行为是返回一个正常页,忽略代码。
curlopt_upload: 如果你想让php为上传做准备,设置这个选项为一个非零值。
curlopt_post : 如果你想php去做一个正规的http post,设置这个选项为一个非零值。这个post是普通的 application/x-www-from-urlencoded 类型,多数被html表单使用。
curlopt_ftplistonly : 设置这个选项为非零值,php将列出ftp的目录名列表。
curlopt_ftpappend : 设置这个选项为一个非零值,php将应用远程文件代替覆盖它。
curlopt_netrc : 设置这个选项为一个非零值,php将在你的 ~./netrc 文件中查找你要建立连接的远程站点的用户名及密码。
curlopt_followlocation : 设置这个选项为一个非零值(象 “location: “)的头,服务器会把它当做http头的一部分发送(注意这是递归的,php将发送形如 “location: “的头)。
curlopt_put : 设置这个选项为一个非零值去用http上传一个文件。要上传这个文件必须设置curlopt_infile和curlopt_infilesize选项.
curlopt_mute : 设置这个选项为一个非零值,php对于curl函数将完全沉默。
curlopt_timeout : 设置一个长整形数,作为最大延续多少秒。
curlopt_low_speed_limit: 设置一个长整形数,控制传送多少字节。
curlopt_low_speed_time : 设置一个长整形数,控制多少秒传送curlopt_low_speed_limit规定的字节数。
curlopt_resume_from : 传递一个包含字节偏移地址的长整形参数,(你想转移到的开始表单)。
curlopt_sslversion: 传递一个包含ssl版本的长参数。默认php将被它自己努力的确定,在更多的安全中你必须手工设置。
curlopt_timecondition : 传递一个长参数,指定怎么处理curlopt_timevalue参数。你可以设置这个参数为timecond_ifmodsince 或 timecond_isunmodsince。这仅用于http。
curlopt_timevalue : 传递一个从1970-1-1开始到现在的秒数。这个时间将被curlopt_timevalue选项作为指定值使用,或被默认timecond_ifmodsince使用。

下列选项的值将被作为字符串:
curlopt_url: 这是你想用php取回的url地址。你也可以在用curl_init()函数初始化时设置这个选项。
curlopt_urpwd : 传递一个形如[urname]:[password]风格的字符串,作用php去连接。
curlopt_proxyurpwd : 传递一个形如[urname]:[password] 格式的字符串去连接http代理。
curlopt_range : 传递一个你想指定的范围。它应该是”x-y”格式,x或y是被除外的。http传送同样支持几个间隔,用逗句来分隔(x-y,n-m)。
curlopt_postfields : 传递一个作为http “post”操作的所有数据的字符串。
curlopt_referer: 在http请求中包含一个”referer”头的字符串。
curlopt_uragent : 在http请求中包含一个”ur-agent”头的字符串。
curlopt_ftpport: 传递一个包含被ftp “post”指令使用的ip地址。这个post指令告诉远程服务器去连接我们指定的ip地址。这个字符串可以是一个ip地址,一个主机名,一个网络界面名(在unix下),或是‘-‘(使用系统默认ip地址)。
curlopt_cookie : 传递一个包含http cookie的头连接。
curlopt_sslcert : 传递一个包含pem格式证书的字符串。
curlopt_sslcertpasswd : 传递一个包含使用curlopt_sslcert证书必需的密码。
curlopt_cookiefile : 传递一个包含cookie数据的文件的名字的字符串。这个cookie文件可以是netscape格式,或是堆存在文件中的http风格的头。
curlopt_customrequest : 当进行http请求时,传递一个字符被get或h水浒传第五回ead使用。为进行delete或其它操作是有益的,更pass a string to be ud instead of get or head when doing an http request. this is uful for doing or another, more obscure, http request. 注意: 在确认你的服务器支持命令先不要去这样做。下列的选项要求一个文件描述(通过使用fopen()函数获得):
curlopt_file: 这个文件将是你放置传送的输出文件,默认是stdout.
curlopt_infile : 这个文件是你传送过来的输入文件。
curlopt_writeheader : 这个文件写有你输出的头部分。
curlopt_stderr : 这个文件写有错误而不是stderr。用来获取需要登录的页面的例子,当前做法是每次或许都登录一次,有需要的人再做改进了.

例一:

复制代码 代码如下:

$cookie_jar = tempnam(‘./tmp’,’cookie’);

$ch = curl_init(); curl_topt($ch,curlopt_url, ‘http://******’);

curl_topt($ch, curlopt_post, 1);

$request = ’email_address=&password=&action=’;

curl_topt($ch, curlopt_postfields, $request); //把返回来的cookie信息保存在$cookie_jar文件中

curl_topt($ch, curlopt_cookiejar, $cookie_jar); //设定返回的数据是否自动显示

curl_topt($ch, curlopt_returntransfer, 1); //设定是否显示头信息

curl_topt($ch, curlopt_header, fal); //设定是否输出页面内容

curl_topt($ch, curlopt_nobody, fal);

curl_exec($ch);

curl_clo($ch); //get data after login

例二:


复制代码 代码如下:

$ch2 = curl_init();

curl_topt($ch2, curlopt_url, ‘http://*****’);

curl_topt($ch2, curlopt_header, fal);

curl_topt($ch2, curlopt_returntransfer, 1);

curl_topt($ch2, curlopt_cookiefile, $cookie_jar);

$orders = curl_exec($ch2);

echo ”;

echo strip_tags($orders);
echo ”;
curl_clo($ch2); 实践证明很稳定:)

例三:


复制代码 代码如下:

t_time_limit(0);

function _rand() {

$length=26;

$chars = “0123456789abcdefghijklmnopqrstuvwxyz”;

$max = strlen($chars) – 1;

mt_srand((double)microtime() * 1000000);

$string = ”;

for($i = 0; $i < $length; $i++) {

$string .= $chars[mt_rand(0, $max)];

}

return $string;

}

$http_ssion=_rand();

echo $http_ssion;

$http_rver=”www.baidu.com”;

$http_url=”/”;

$ch = curl_init();

curl_topt ($ch,curlopt_url,”http://”.$http_rver.$http_url);

curl_topt($ch,curlopt_returntransfer,true);

curl_topt($ch,curlopt_uragent,”mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; sv1; .net clr 1.1.4322; .net clr 2.0.50727)”);

//curl_topt($ch,curlopt_cookie,$http_ssion);

$res = curl_exec($ch);

curl_clo ($ch);

print_r($res);

刷论坛代码:

1、抓cookies程序:


复制代码 代码如下:

$url=”http://www.yoururl.com/bbs/login.asp?action=chk”;

//填入论坛的登陆页面地址

$ch = curl_init();

curl_topt($ch,curlopt_url,$url);

curl_topt($ch,curlopt_referer,”http://www.hxfoods.com/bbs/login.asp”);

//设置,访问页面的来源地址

curl_topt($ch,curlopt_post,1);
curl_topt($ch,curlopt_postfields,’urname=→→敢死队→&password=168168′);
//分析登陆页面,把用户名,密码分别对应起来
curl_topt ($ch, curlopt_header,true);
//使能显示http头,
curl_exec($ch);
if (curl_errno($ch))
{
print curl_error($ch);
}
el
{
curl_clo($ch);
}

2、刷楼了:


复制代码 代码如下:

请假单模板t_time_limit(0);

//设置程序执行时间无限制

$i=10000;

//耍10000次

for($j=0;$j<$i;$j++)

{

$url=”http://www.yoururl.com/bbs/savepost.asp”;

//这个地址是回复表单里面action的url地址

$ch = curl_init();

curl_topt($ch,curlopt_url,$url);

curl_topt($ch,curlopt_referer,”http://www.hxfoods.com/bbs/dispbbs.asp?boardid=14&replyid=672709&id=127437&page=1&skin=0&star=53″);

//设置来源地址,如果不设置,论坛服务器有可能有验证不允许回复

curl_topt($ch,curlopt_cookiession,true);

//能保存cookie

curl_topt($ch,curlopt_cookie,”dvforum=urid=24122&urcookies=0&urhidden=2&password=w0reu3g775vry745&urclass=%96%7c&urname=%a1%fa%a1%fa%b8%d2%cb%c0%b6%d3%a1%fa&staturid=2194783945 “);

//这儿就是设置cookie了

curl_topt($ch,curlopt_post,1);

curl_topt($ch,curlopt_nobody,1);

//不显示内容,因为有很多论坛回复后要自动跳转。

curl_topt($ch,curlopt_postfields,’body=gfdfgdfgasdfgdfgdfgdfg& followup=672709&rootid=127437&star=58&totalutable=dv_bbs3& amp;urname=→→敢死队→&signflag=1&total=65535′);

//把你分析的回复表单的参数分别赋值

curl_topt ($ch, curlopt_header,true);

curl_exec($ch);

if (curl_errno($ch))

{

print curl_error($ch);

}

el

{

curl_clo($ch);

}

}

curl相关函数

curl_clo — 关闭一个curl会话
curl_copy_handle — 拷贝一个curl连接资源的所有内容和参数
curl_errno — 返回一个包含当前会话错误信息的数字编号
curl_error — 返回一个包含当前会话错误信息的字符串
curl_exec — 执行一个curl会话
curl_getinfo — 获取一个curl连接资源句柄的信息
curl_init — 初始化一个curl会话
curl_multi_add_handle — 向curl批处理会话中添加单独的curl句柄资源
curl_multi_clo — 关闭一个批处理句柄资源
curl_multi_exec — 解析一个curl批处理句柄
curl_multi_getcontent — 返回获取的输出的文本流
curl_multi_info_read — 获取当前解析的curl的相关传输信息
curl_multi_失望init — 初始化一个curl批处理句柄资源
curl_multi_remove_handle — 移除curl批处理句柄资源中的某个句柄资源
curl_multi_lect — get all the sockets associated with the curl extension, which can then be “lected”
curl_topt_array — 以数组的形式为一个curl设置会话参数
curl_topt — 为一个curl设置会话参数
curl_version — 获取curl相关的版本信息

curl_init()函数的作用初始化一个curl会话,curl_init()函数唯一的一个参数是可选的,表示一个url地址。
curl_exec()函数的作用是执行一个curl会话,唯一的参数是curl_init()函数返回的句柄。
curl_clo()函数的作用是关闭一个curl会话,唯一的参数是curl_init()函数返回的句柄。

$ch = curl_init(“http://www.baidu.com/”);
curl_exec($ch);
curl_clo($ch);
curl_version()函数的作用是获取curl相关的版本信息,curl_version()函数有一个参数,不清楚是做什么的

print_r(curl_version())
curl_getinfo()函数的作用是获取一个curl连接资源句柄的信息,curl_getinfo()函数有两个参数,第一个参数是curl的资源句柄,第二个参数是下面一些常量:

$ch = curl_init(“http://www.baidu.com/”);
print_r(curl_getinfo($ch));
可选的常量包括:
curlinfo_effective_url
最后一个有效的url地址
curlinfo_http_code
最后一个收到的http代码
curlinfo_filetime
远程获取文档的时间,如果无法获取,则返回值为“-1”
curlinfo_total_time
最后一次传输所消耗的时间
curlinfo_namelookup_time
名称解析所消耗的时间
curlinfo_connect_time
建立连接所消耗的时间
curlinfo_pretransfer_time
从建立连接到准备传输所使用的时间
curlinfo_starttransfer_time
从建立连接到传输开始所使用的时间
curlinfo_redirect_time
在事务传输开始前重定向所使用的时间
curlinfo_size_upload
上传数据量的总值
curlinfo_size_download
下载数据量的总值
curlinfo_speed_download
平均下载速度
curlinfo_speed_upload
平均上传速度
curlinfo_header_size
header部分的大小
curlinfo_header_out
发送请求的字符串
curlinfo_request_size
在http请求中有问题的请求的大小
curlinfo_ssl_verifyresult
result of ssl certification verification requested by tting curlopt_ssl_verifypeer
curlinfo_content_length_download
从content-length: field中读取的下载内容长度
curlinfo_content_length_upload
上传内容大小的说明
curlinfo_content_type
下载内容的“content-type”值,null表示服务器没有发送有效的“content-type: header”
curl_topt()函数的作用是为一个curl设置会话参数。curl_topt_array()函数的作用是以数组的形式为一个curl设置会话参数。

$ch = curl_init();
$fp = fopen(“example_homepage.txt”, “w”);
curl_topt($ch, curlopt_file, $fp);
$options = array(
curlopt_url => ‘http://www.baidu.com/’,
curlo顿丘pt_header => fal
);
curl_topt_array($ch, $options);
curl_exec($ch);
curl_clo($ch);
fclo($fp);
可设置的参数有:
curlopt_autoreferer
自动设置header中的referer信息
curlopt_binarytransfer
在启用curlopt_returntransfer时候将获取数据返回
curlopt_cookiession
启用时curl会仅仅传递一个ssion cookie,忽略其他的cookie,默认状况下curl会将所有的cookie返回给服务端。ssion cookie是指那些用来判断服务器端的ssion是否有效而存在的cookie。
curlopt_crlf
启用时将unix的换行符转换成回车换行符。
curlopt_dns_u_global_cache
启用时会启用一个全局的dns缓存,此项为线程安全的,并且默认为true。
curlopt_failonerror
显示http状态码,默认行为是忽略编号小于等于400的http信息
curlopt_filetime
启用时会尝试修改远程文档中的信息。结果信息会通过curl_getinfo()函数的curlinfo_filetime选项返回。
curlopt_followlocation
启用时会将服务器服务器返回的“location:”放在header中递归的返回给服务器,使用curlopt_maxredirs可以限定递归返回的数量。
curlopt_forbid_reu
在完成交互以后强迫断开连接,不能重用。
curlopt_fresh_connect
强制获取一个新的连接,替代缓存中的连接。
curlopt_ftp_u_eprt
true to u eprt (and lprt) when doing active ftp downloads. u fal to disable eprt and lprt and u port only.
added in php 5.0.0.
curlopt_ftp_u_epsv
true to first try an epsv command for ftp transfers before reverting back to pasv. t to fal to disable epsv.
curlopt_ftpappend
true to append to the remote file instead of overwriting it.
curlopt_ftpascii
an alias of curlopt_transfertext. u that instead.
curlopt_ftplistonly
true to only list the names of an ftp directory.
curlopt_header
启用时会将头文件的信息作为数据流输出。
curlopt_httpget
启用时会设置http的method为get,因为get是默认是,所以只在被修改的情况下使用。
curlopt_httpproxytunnel
启用时会通过http代理来传输。
curlopt_mute
讲curl函数中所有修改过的参数恢复默认值。
curlopt_netrc
在连接建立以后,访问~/.netrc文件获取用户名和密码信息连接远程站点。
curlopt_nobody
启用时将不对html中的body部分进行输出。
curlopt_noprogress
启用时关闭curl传输的进度条,此项的默认设置为true
curlopt_nosignal
启用时忽略所有的curl传递给php进行的信号。在sapi多线程传输时此项被默认打开。
curlopt_post
启用时会发送一个常规的post请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样。
curlopt_put
启用时允许http发送文件,必须同时设置curlopt_infile和curlopt_infilesize
curlopt_returntransfer
讲curl_exec()获取的信息以文件流的形式返回,而不是直接输出。
curlopt_ssl_verifypeer
fal to stop curl from verifying the peer’s certificate. alternate certificates to verify against can be specified with the curlopt_cainfo option or a certificate directory can be specified with the curlopt_capath option. curlopt_ssl_verifyhost may also need to be true or fal if curlopt_ssl_verifypeer is disabled (it defaults to 2). true by default as of curl 7.10. default bundle installed as of curl 7.10.
curlopt_transfertext
true to u ascii mode for ftp transfers. for ldap, it retrieves data in plain text instead of html. on windows systems, it will not t stdout to binary mode.
curlopt_unrestricted_auth
在使用curlopt_followlocation产生的header中的多个locations中持续追加用户名和密码信息,即使域名已发生改变。
curlopt_upload
启用时允许文件传输
curlopt_verbo
启用时会汇报所有的信息,存放在stderr或指定的curlopt_stderr中
curlopt_buffersize
每次获取的数据中读入缓存的大小,这个值每次都会被填满。
curlopt_clopolicy
不是curlclopolicy_least_recently_ud就是curlclopolicy_oldest,还存在另外三个,但是curl暂时还不支持。.
curlopt_connecttimeout
在发起连接前等待的时间,如果设置为0,则不等待。
curlopt_dns_cache_timeout
设置在内存中保存dns信息的时间,默认为120秒。
curlopt_ftpsslauth
the ftp authentication method (when is activated): curlftpauth_ssl (try ssl first), curlftpauth_tls (try tls first), or curlftpauth_default (let curl decide).
curlopt_http_version
设置curl使用的http协议,curl_http_version_none(让curl自己判断),curl_http_version_1_0(http/1.0),curl_http_version_1_1(http/1.1)
curlopt_httpauth
使用的http验证方法,可选的值 有:curlauth_basic,curlauth_digest,curlauth_gssnegotiate,curlauth_ntlm,curlauth_any,curlauth_anysafe, 可以使用“|”操作符分隔多个值,curl让服务器选择一个支持最好的值,curlauth_any等价于curlauth_basic | curlauth_digest | curlauth_gssnegotiate | curlauth_ntlm,curlauth_anysafe等价于curlauth_digest | curlauth_gssnegotiate | curlauth_ntlm
curlopt_infilesize
设定上传文件的大小
curlopt_low_speed_limit
当传输速度小于curlopt_low_speed_limit时,php会根据curlopt_low_speed_time来判断是否因太慢而取消传输。
curlopt_low_speed_time
the number of conds the transfer should be below curlopt_low_speed_limit for php to consider the transfer too slow and abort.
当传输速度小于curlopt_low_speed_limit时,php会根据curlopt_low_speed_time来判断是否因太慢而取消传输。
curlopt_maxconnects
允许的最大连接数量,超过是会通过curlopt_clopolicy决定应该停止哪些连接
curlopt_maxredi十四大时间rs
指定最多的http重定向的数量,这个选项是和curlopt_followlocation一起使用的。
curlopt_port
一个可选的用来指定连接端口的量
curlopt_proxyauth
the http authentication method(s) to u for the proxy connection. u the same bitmasks as described in curlopt_httpauth. for proxy authentication, only curlauth_basic and curlauth_ntlm are currently supported.
curlopt_proxyport
the port number of the proxy to connect to. this port number can also be t in curlopt_proxy.
curlopt_proxytype
either curlproxy_http (default) or curlproxy_socks5.
curlopt_resume_from
在恢复传输时传递一个字节偏移量(用来断点续传)
curlopt_ssl_verifyhost
1 to check the existence of a common name in the ssl peer certificate.
2 to check the existence of a common name and also verify that it matches the hostname provided.
curlopt_sslversion
the ssl version (2 or 3) to u. by default php will try to determine this itlf, although in some cas this must be t manually.
curlopt_timecondition
如果在curlopt_timevalue指定的某个时间以后被编辑过,则使用curl_timecond_ifmodsince返回页面,如果没有被修 改过,并且curlopt_header为true,则返回一个”304 not modified”的header,curlopt_header为fal,则使用curl_timecond_isunmodsince,默认值为 curl_timecond_ifmodsince
curlopt_timeout
设置curl允许执行的最长秒数
curlopt_timevalue
设置一个curlopt_timecondition使用的时间戳,在默认状态下使用的是curl_timecond_ifmodsince
curlopt_cainfo
the name of a file holding one or more certificates to verify the peer with. this only makes n when ud in combination with curlopt_ssl_verifypeer.
curlopt_capath
a directory that holds multiple ca certificates. u this option alongside curlopt_ssl_verifypeer.
curlopt_cookie
设定http请求中“t-cookie:”部分的内容。
curlopt_cookiefile
包含cookie信息的文件名称,这个cookie文件可以是netscape格式或者http风格的header信息。
curlopt_cookiejar
连接关闭以后,存放cookie信息的文件名称
curlopt_customrequest
a custom request method to u instead of “get” or “head” when doing a http request. this is uful for doing “delete” or other, more obscure http requests. valid values are things like “get”, “post”, “connect” and so on; i.e. do not enter a whole http request line here. for instance, entering “get /index.html http/1.0\r\n\r\n” would be incorrect.
note: don’t do this without making sure the rver supports the custom request method first.
curlopt_egbsocket
like curlopt_random_file, except a filename to an entropy gathering daemon socket.
curlopt_encoding
header中“accept-encoding: ”部分的内容,支持的编码格式为:”identity”,”deflate”,”gzip”。如果设置为空字符串,则表示支持所有的编码格式
curlopt_ftpport
the value which will be ud to get the ip address to u for the ftp “post” instruction. the “post” instruction tells the remote rver to connect to our specified ip address. the string may be a plain ip address, a hostname, a network interface name (under unix), or just a plain ‘-‘ to u the systems default ip address.
curlopt_interface
在外部网络接口中使用的名称,可以是一个接口名,ip或者主机名。
curlopt_krb4level
krb4(kerberos 4)安全级别的设置,可以是一下几个值之一:”clear”,”safe”,”confidential”,”private”。默认的值 为”private”,设置为null的时候表示禁用krb4,现在krb4安全仅能在ftp传输中使用。
curlopt_postfields
在http中的“post”操作。如果要传送一个文件,需要一个@开头的文件名
curlopt_proxy
设置通过的http代理服务器
curlopt_proxyurpwd
连接到代理服务器的,格式为“[urname]:[password]”的用户名和密码。
curlopt_random_file
设定存放ssl用到的随机数种子的文件名称
curlopt_range
设置http传输范围,可以用“x-y”的形式设置一个传输区间,如果有多个http传输,则使用逗号分隔多个值,形如:”x-y,n-m”。
curlopt_referer
设置header中”referer: ” 部分的值。
curlopt_ssl_cipher_list
a list of ciphers to u for ssl. for example, rc4-sha and tlsv1 are valid cipher lists.
curlopt_sslcert
传递一个包含pem格式证书的字符串。
curlopt_sslcertpasswd
传递一个包含使用curlopt_sslcert证书必需的密码。
curlopt_sslcerttype
the format of the certificate. supported formats are “pem” (default), “der”, and “eng”.
curlopt_sslengine
the identifier for the crypto engine of the private ssl key specified in curlopt_sslkey.
curlopt_sslengine_default
the identifier for the crypto engine ud for asymmetric crypto operations.
curlopt_sslkey
the name of a file containing a private ssl key.
curlopt_sslkeypasswd
the cret password needed to u the private ssl key specified in curlopt_sslkey.
note: since this option contains a nsitive password, remember to keep the php script it is contained within safe.
curlopt_sslkeytype
the key type of the private ssl key specified in curlopt_sslkey. supported key types are “pem” (default), “der”, and “eng”.
curlopt_url
需要获取的url地址,也可以在php的curl_init()函数中设置。
curlopt_uragent
在http请求中包含一个”ur-agent”头的字符串。
curlopt_urpwd
传递一个连接中需要的用户名和密码,格式为:“[urname]:[password]”。
curlopt_http200alias
设置不再以error的形式来处理http 200的响应,格式为一个数组。
curlopt_httpheader
设置一个header中传输内容的数组。
curlopt_postquote
an array of ftp commands to execute on the rver after the ftp request has been performed.
curlopt_quote
an array of ftp commands to execute on the rver prior to the ftp request.
curlopt_file
设置输出文件的位置,值是一个资源类型,默认为stdout (浏览器)。
curlopt_infile
在上传文件的时候需要读取的文件地址,值是一个资源类型。
curlopt_stderr
设置一个错误输出地址,值是一个资源类型,取代默认的stderr。
curlopt_writeheader
设置header部分内容的写入的文件地址,值是一个资源类型。
curlopt_headerfunction
设置一个回调函数,这个函数有两个参数,第一个是curl的资源句柄,第二个是输出的header数据。header数据的输出必须依赖这个函数,返回已写入的数据大小。
curlopt_passwdfunction
设置一个回调函数,有三个参数,第一个是curl的资源句柄,第二个是一个密码提示符,第三个参数是密码长度允许的最大值。返回密码的值。
curlopt_readfunction
设置一个回调函数,有两个参数,第一个是curl的资源句柄,第二个是读取到的数据。数据读取必须依赖这个函数。返回读取数据的大小,比如0或者eof。
curlopt_writefunction
设置一个回调函数,有两个参数,第一个是curl的资源句柄,第二个是写入的数据。数据写入必须依赖这个函数。返回精确的已写入数据的大小
curl_copy_handle()函数的作用是拷贝一个curl连接资源的所有内容和参数

$ch = curl_init(“http://www.baidu.com/”);
$another = curl_copy_handle($ch);
curl_exec($another);
curl_clo($another);
curl_error()函数的作用是返回一个包含当前会话错误信息的字符串。
curl_errno()函数的作用是返回一个包含当前会话错误信息的数字编号。
curl_multi_init()函数的作用是初始化一个curl批处理句柄资源。
curl_multi_add_handle()函数的作用是向curl批处理会话中添加单独的curl句柄资源。curl_multi_add_handle()函数有两个参数,第一个参数表示一个curl批处理句柄资源,第二个参数表示一个单独的curl句柄资源。
curl_multi_exec()函数的作用是解析一个curl批处理句柄,curl_multi_exec()函数有两个参数,第一个参数表示一个批处理句柄资源,第二个参数是一个引用值的参数,表示剩余需要处理的单个的curl句柄资源数量。
curl_multi_remove_handle()函数表示移除curl批处理句柄资源中的某个句柄资源,curl_multi_remove_handle()函数有两个参数,第一个参数表示一个curl批处理句柄资源,第二个参数表示一个单独的curl句柄资源。
curl_multi_clo()函数的作用是关闭一个批处理句柄资源。

$ch1 = curl_init();
$ch2 = curl_init();
curl_topt($ch1, curlopt_url, “http://www.baidu.com/”);
curl_topt($ch1, curlopt_header, 0);
curl_topt($ch2, curlopt_url, “http://www.google.com/”);
curl_topt($ch2, curlopt_header, 0);
$mh = curl_multi_init();
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
do {
curl_multi_exec($mh,$flag);
} while ($flag > 0);
curl_multi_remove_handle($mh,$ch1);
curl_multi_remove_handle($mh,$ch2);
curl_multi_clo($mh);
curl_multi_getcontent()函数的作用是在设置了curlopt_returntransfer的情况下,返回获取的输出的文本流。
curl_multi_info_read()函数的作用是获取当前解析的curl的相关传输信息。
curl_multi_lect()
get all the sockets associated with the curl extension, which can then be “lected”

本文发布于:2023-04-06 10:47:59,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/a1847a04734a2b99fd12db5f714ef010.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:PHP中CURL方法curl.doc

本文 PDF 下载地址:PHP中CURL方法curl.pdf

标签:函数   句柄   参数   选项
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图