php curl.dll程序执行出现异常

页面跳转错误Warning: curl_setopt() [function.curl-setopt]:拓荒博客 | 拓荒博客
&&&&页面跳转错误Warning: curl_setopt() [function.curl-setopt]:
提交于 19:35:43页面跳转出现错误,显示为以下代码:
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in/home/xiaomin0/public_html/wp-content/plugins/baidusubmit/inc/sitemap.php on line 521
Warning: Cannot modify header information – headers already sent by (output started at /home/xiaomin0/public_html/wp-content/plugins/baidusubmit/inc/sitemap.php:521) in /home/xiaomin0/public_html/wp-includes/pluggable.php on line 896
【博主回复】:
很明显你这个是插件中含有需要调用PHP开启相关CURL扩展模块的部分,其实你没必要用这种插件,卸载掉这个插件或者开启CURL扩展模块就可解决本问题。PHP之php_curl.dll错误解决方法
Windows下面php5找不到php_curl.dll的问题由于要用到Curl,所以设置的时候提示这样的错误:unable to load dynamic library ‘….php_curl.dll’我的环境是Apache/2.2.14 (Win32) /5.3.0,按理说php5的安装是很简单的,直接指定extension_dir = “c:/php523/ext/”就可以了,像gd2, i和mysql_dll都没问题,唯独 php_curl.dll总是提示出错。试着修改PATH路径,把DLL复制到//system32/,还是提示找不到 php_curl.dll。最后,终于在php.net上找到这么一句话: Note to Win32 Users: In order to enable this module on a Windows environment, libeay32.dll and ssleay32.dll must be present in your PATH.在php根目录找到这两个文件,复制 libeay32.dll 和 ssleay32.dll到/windows/system32/,终于搞定,phpinfo出现如下信息:cURL support enabledcURL Information 7.19.4
您对本文章有什么意见或着疑问吗?请到您的关注和建议是我们前行的参考和动力&&
您的浏览器不支持嵌入式框架,或者当前配置为不显示嵌入式框架。PHP cURL遇到SSL CA验证问题,本地正常,部署总是返回FALSE | 马铖的博客-MaCheng's Blog.
欢迎来到我的博客!
我使用WordPress构建我的Blog,并发布我的一些博文。
内容包括技术类的以及学习生活类的一些文章。PHP程序错误调试方法 让php显示错误提示-Php常用代码-Php教程-壹聚教程网PHP程序错误调试方法 让php显示错误提示公司的服务器用的是wdcp搭建的环境,安装非常方便,但是在开发的过程可能把函数名之内的东西写错了,服务器直接返回的是500错误,没有任何错误提示,只是告诉你500错误,很让人头疼,这样调试错误很不方便,注意这里我关掉了浏览器的显示 友好错误 这个时候我们需要修改php.ini配置文件,不知道配置文件在那里,请用phpinfo() 然后搜索一下php.ini,你就能看到php.ini的位置了
查找:display_errors 将值设置成on
display_errors = on
error_reporting = E_ALL & ~E_DEPRECATED
如果我们在php.ini中打开了错误提示还是不行你的程序可能有错误开关了,如下
//禁用错误报告&
error_reporting(0);&
//报告运行时错误&
error_reporting(E_ERROR | E_WARNING | E_PARSE);&
//报告所有错误&
error_reporting(E_ALL);&
如果你程序中有这段代码我们只要去掉就可以了哦
PHP NOTICE级错误提示对程序性能影响的研究
下面我来用性能测试来证明这个推论:
在关闭错误显示的情况下,测试未初始化变量和已初始化变量在次循环中的性能
变量已初始化的循环代码如下:
变量未初始化的循环代码如下:
测试成绩:
初始化:平均 5.28 秒
未初始化:平均 17.2 秒
性能差距:3.25倍
在关闭错误显示的情况下,测试数组索引使用引号和非引号引用在次循环中的性能
数组有引号索引代码如下:
数组无引号索引代码如下:
测试成绩:
有引号:平均 6.37 秒
无引号:平均 25.19秒
性能差距:3.95倍
平均时间表:
从上面例子可以看出如果页面错误太多会导致页面性能下降哦,所以我们尽量不要使用关闭错误来处理php错误问题我们要保证页面没有错误才行哦。
上一页: &&&&&下一页:相关内容PHP CURL HTTP 研究笔记
当前位置:>>>资讯:PHP CURL HTTP 研究笔记
PHP CURL HTTP 研究笔记
2 &&?php& 3 /**& 4 * CURL HTTP请求工具,& 5 * 作者:袁维& 6 * 参考:郑GG的BLOG& 7 * 支持以下功能:& 8 * 1:支持ssl连接和proxy代理连接& 9 * 2: 对cookie的自动支持 10 * 3: 简单的GET/POST常规操作 11 * 4: 支持单个文件上传或同字段的多文件上传,支持相对路径或绝对路径. 12 * 5: 支持返回发送请求前和请求后所有的服务器信息和服务器Header信息 13 * 6: 自动支持lighttpd服务器 14 * 7: 支持自动设置 REFERER 引用页 15 * 8: 自动支持服务器301跳转或重写问题(谢谢郑GG) 16 * 9: 其它可选项,如自定义端口,超时时间,USERAGENT,Gzip压缩等. 17 */ 18 class Curl{ 19
20 //CURL句柄 21 private $ch = null; 22 //CURL执行前后所设置或服务器端返回的信息 23 private $info = array(); 24 //CURL SETOPT 信息 25 private $setopt = array( 26 //访问的端口,http默认是 80 27 'port'=&<span style="COLOR: #, 28 //客户端 USERAGENT,如:&Mozilla/4.0&,为空则使用用户的浏览器 29 'userAgent'=&'', 30 //连接超时时间 31 'timeOut'=&<span style="COLOR: #, 32 //是否使用 COOKIE 建议打开,因为一般网站都会用到 33 'useCookie'=&true, 34 //是否支持SSL 35 'ssl'=&false, 36 //客户端是否支持 gzip压缩 37 'gzip'=&true, 38
39 //是否使用代理 40 'proxy'=&false, 41 //代理类型,可选择 HTTP 或 SOCKS5 42 'proxyType'=&'HTTP', 43 //代理的主机地址,如果是 HTTP 方式则要写成URL形式如:&& 44 //SOCKS5 方式则直接写主机域名为IP的形式,如:&192.168.1.1& 45 'proxyHost'=&'', 46 //代理主机的端口 47 'proxyPort'=&<span style="COLOR: #34, 48 //代理是否要身份认证(HTTP方式时) 49 'proxyAuth'=&false, 50 //认证的方式.可选择 BASIC 或 NTLM 方式 51 'proxyAuthType'=&'BASIC', 52 //认证的用户名和密码 53 'proxyAuthUser'=&'user', 54 'proxyAuthPwd'=&'password', 55 ); 56
57 /** 58 * 构造函数 59 * 60 * @param array $setopt :请参考 private $setopt 来设置 61 */ 62 public function __construct($setopt=array()) 63 { 64 //合并用户的设置和系统的默认设置 65 $this-&setopt = array_merge($this-&setopt,$setopt); 66 //如果没有安装CURL则终止程序 67 function_exists('curl_init') || die('CURL Library Not Loaded'); 68 //初始化 69 $this-&ch = curl_init(); 70 //设置CURL连接的端口 71 curl_setopt($this-&ch, CURLOPT_PORT, $this-&setopt['port']); 72 //使用代理 73 if($this-&setopt['proxy']){ 74 $proxyType = $this-&setopt['proxyType']=='HTTP' ? CURLPROXY_HTTP : CURLPROXY_SOCKS5; 75 curl_setopt($this-&ch, CURLOPT_PROXYTYPE, $proxyType); 76 curl_setopt($this-&ch, CURLOPT_PROXY, $this-&setopt['proxyHost']); 77 curl_setopt($this-&ch, CURLOPT_PROXYPORT, $this-&setopt['proxyPort']); 78 //代理要认证 79 if($this-&setopt['proxyAuth']){ 80 $proxyAuthType = $this-&setopt['proxyAuthType']=='BASIC' ? CURLAUTH_BASIC : CURLAUTH_NTLM; 81 curl_setopt($this-&ch, CURLOPT_PROXYAUTH, $proxyAuthType); 82 $user = &[{$this-&setopt['proxyAuthUser']}]:[{$this-&setopt['proxyAuthPwd']}]&; 83 curl_setopt($this-&ch, CURLOPT_PROXYUSERPWD, $user); 84 } 85 } 86 //启用时会将服务器服务器返回的&Location:&放在header中递归的返回给服务器 87 curl_setopt($this-&ch, CURLOPT_FOLLOWLOCATION, true); 88 //打开的支持SSL 89 if($this-&setopt['ssl']){ 90 //不对认证证书来源的检查 91 curl_setopt($this-&ch, CURLOPT_SSL_VERIFYPEER, false); 92 //从证书中检查SSL加密算法是否存在 93 curl_setopt($this-&ch, CURLOPT_SSL_VERIFYHOST, true); 94 } 95 //设置http头,支持lighttpd服务器的访问 96 $header[]= 'Expect:'; 97 curl_setopt($this-&ch, CURLOPT_HTTPHEADER, $header); 98 //设置 HTTP USERAGENT 99 $userAgent = $this-&setopt['userAgent'] ? $this-&setopt['userAgent'] : $_SERVER['HTTP_USER_AGENT'];<span style="COLOR: #0 curl_setopt($this-&ch, CURLOPT_USERAGENT, $userAgent);<span style="COLOR: #1 //设置连接等待时间,0不等待<span style="COLOR: #2 curl_setopt($this-&ch, CURLOPT_CONNECTTIMEOUT, $this-&setopt['timeOut']);<span style="COLOR: #3 //设置curl允许执行的最长秒数<span style="COLOR: #4 curl_setopt($this-&ch, CURLOPT_TIMEOUT, $this-&setopt['timeOut']);<span style="COLOR: #5 //设置客户端是否支持 gzip压缩<span style="COLOR: #6 if($this-&setopt['gzip']){<span style="COLOR: #7 curl_setopt($this-&ch, CURLOPT_ENCODING, 'gzip');<span style="COLOR: #8 }<span style="COLOR: #9 //是否使用到COOKIE<span style="COLOR: #0 if($this-&setopt['useCookie']){<span style="COLOR: #1 //生成存放临时COOKIE的文件(要绝对路径)<span style="COLOR: #2 $cookfile = tempnam(sys_get_temp_dir(),'cuk');<span style="COLOR: #3 //连接关闭以后,存放cookie信息<span style="COLOR: #4 curl_setopt($this-&ch, CURLOPT_COOKIEJAR, $cookfile);<span style="COLOR: #5 curl_setopt($this-&ch, CURLOPT_COOKIEFILE, $cookfile);<span style="COLOR: #6 }<span style="COLOR: #7 //是否将头文件的信息作为数据流输出(HEADER信息),这里保留报文<span style="COLOR: #8 curl_setopt($this-&ch, CURLOPT_HEADER, true);<span style="COLOR: #9 //获取的信息以文件流的形式返回,而不是直接输出。<span style="COLOR: #0 curl_setopt($this-&ch, CURLOPT_RETURNTRANSFER, true) ;<span style="COLOR: #1 curl_setopt($this-&ch, CURLOPT_BINARYTRANSFER, true) ;<span style="COLOR: #2 }<span style="COLOR: #3 <span style="COLOR: #4 /**<span style="COLOR: #5 * 以 GET 方式执行请求<span style="COLOR: #6 *<span style="COLOR: #7 * @param string $url :请求的URL<span style="COLOR: #8 * @param array $params :请求的参数,格式如: array('id'=&10,'name'=&'yuanwei')<span style="COLOR: #9 * @param array $referer :引用页面,为空时自动设置,如果服务器有对这个控制的话则一定要设置的.<span style="COLOR: #0 * @return 错误返回:false 正确返回:结果内容<span style="COLOR: #1 */<span style="COLOR: #2 public function get($url,$params=array(), $referer='')<span style="COLOR: #3 {<span style="COLOR: #4 return $this-&_request('GET', $url, $params, array(), $referer);<span style="COLOR: #5 }<span style="COLOR: #6 <span style="COLOR: #7 /**<span style="COLOR: #8 * 以 POST 方式执行请求<span style="COLOR: #9 *<span style="COLOR: #0 * @param string $url :请求的URL<span style="COLOR: #1 * @param array $params :请求的参数,格式如: array('id'=&10,'name'=&'yuanwei')<span style="COLOR: #2 * @param array $uploadFile :上传的文件,支持相对路径,格式如下<span style="COLOR: #3 * 单个文件上传:array('img1'=&'./file/a.jpg')<span style="COLOR: #4 * 同字段多个文件上传:array('img'=&array('./file/a.jpg','./file/b.jpg'))<span style="COLOR: #5 * @param array $referer :引用页面,引用页面,为空时自动设置,如果服务器有对这个控制的话则一定要设置的.<span style="COLOR: #6 * @return 错误返回:false 正确返回:结果内容<span style="COLOR: #7 */<span style="COLOR: #8 public function post($url,$params=array(),$uploadFile=array(), $referer='')<span style="COLOR: #9 {<span style="COLOR: #0 return $this-&_request('POST', $url, $params, $uploadFile, $referer);<span style="COLOR: #1 }<span style="COLOR: #2 <span style="COLOR: #3 /**<span style="COLOR: #4 * 得到错误信息<span style="COLOR: #5 *<span style="COLOR: #6 * @return string<span style="COLOR: #7 */<span style="COLOR: #8 public function error()<span style="COLOR: #9 {<span style="COLOR: #0 return curl_error($this-&ch);<span style="COLOR: #1 }<span style="COLOR: #2 <span style="COLOR: #3 /**<span style="COLOR: #4 * 得到错误代码<span style="COLOR: #5 *<span style="COLOR: #6 * @return int<span style="COLOR: #7 */<span style="COLOR: #8 public function errno()<span style="COLOR: #9 {<span style="COLOR: #0 return curl_errno($this-&ch);<span style="COLOR: #1 }<span style="COLOR: #2 <span style="COLOR: #3 /**<span style="COLOR: #4 * 得到发送请求前和请求后所有的服务器信息和服务器Header信息,其中<span style="COLOR: #5 * [before] :请求前所设置的信息<span style="COLOR: #6 * [after] :请求后所有的服务器信息<span style="COLOR: #7 * [header] :服务器Header报文信息<span style="COLOR: #8 *<span style="COLOR: #9 * @return array<span style="COLOR: #0 */<span style="COLOR: #1 public function getInfo()<span style="COLOR: #2 {<span style="COLOR: #3 return $this-&<span style="COLOR: #4 }<span style="COLOR: #5 <span style="COLOR: #6 /**<span style="COLOR: #7 * 析构函数<span style="COLOR: #8 *<span style="COLOR: #9 */<span style="COLOR: #0 public function __destruct()<span style="COLOR: #1 {<span style="COLOR: #2 //关闭CURL<span style="COLOR: #3 curl_close($this-&ch);<span style="COLOR: #4 }<span style="COLOR: #5 <span style="COLOR: #6 /**<span style="COLOR: #7 * 私有方法:执行最终请求<span style="COLOR: #8 *<span style="COLOR: #9 * @param string $method :HTTP请求方式<span style="COLOR: #0 * @param string $url :请求的URL<span style="COLOR: #1 * @param array $params :请求的参数<span style="COLOR: #2 * @param array $uploadFile :上传的文件(只有POST时才生效)<span style="COLOR: #3 * @param array $referer :引用页面<span style="COLOR: #4 * @return 错误返回:false 正确返回:结果内容<span style="COLOR: #5 */<span style="COLOR: #6 private function _request($method, $url, $params=array(), $uploadFile=array(), $referer='')<span style="COLOR: #7 {<span style="COLOR: #8 //如果是以GET方式请求则要连接到URL后面<span style="COLOR: #9 if($method == 'GET'){<span style="COLOR: #0 $url = $this-&_parseUrl($url,$params);<span style="COLOR: #1 }<span style="COLOR: #2 //设置请求的URL<span style="COLOR: #3 curl_setopt($this-&ch, CURLOPT_URL, $url);<span style="COLOR: #4 //如果是POST<span style="COLOR: #5 if($method == 'POST'){<span style="COLOR: #6 //发送一个常规的POST请求,类型为:application/x-www-form-urlencoded<span style="COLOR: #7 curl_setopt($this-&ch, CURLOPT_POST, true) ;<span style="COLOR: #8 //设置POST字段值<span style="COLOR: #9 $postData = $this-&_parsmEncode($params,false);<span style="COLOR: #0 //如果有上传文件<span style="COLOR: #1 if($uploadFile){<span style="COLOR: #2 foreach($uploadFile as $key=&$file){<span style="COLOR: #3 if(is_array($file)){<span style="COLOR: #4 $n = <span style="COLOR: #;<span style="COLOR: #5 foreach($file as $f){<span style="COLOR: #6 //文件必需是绝对路径<span style="COLOR: #7 $postData[$key.'['.$n++.']'] = '@'.realpath($f);<span style="COLOR: #8 }<span style="COLOR: #9 }else{<span style="COLOR: #0 $postData[$key] = '@'.realpath($file);<span style="COLOR: #1 }<span style="COLOR: #2 }<span style="COLOR: #3 }<span style="COLOR: #4 //pr($postData);<span style="COLOR: #5 curl_setopt($this-&ch, CURLOPT_POSTFIELDS, $postData);<span style="COLOR: #6 }<span style="COLOR: #7 //设置了引用页,否则自动设置<span style="COLOR: #8 if($referer){<span style="COLOR: #9 curl_setopt($this-&ch, CURLOPT_REFERER, $referer);<span style="COLOR: #0 }else{<span style="COLOR: #1 curl_setopt($this-&ch, CURLOPT_AUTOREFERER, true);<span style="COLOR: #2 }<span style="COLOR: #3 //得到所有设置的信息<span style="COLOR: #4 $this-&info['before'] = curl_getinfo($this-&ch);<span style="COLOR: #5 //开始执行请求<span style="COLOR: #6 $result = curl_exec($this-&ch);<span style="COLOR: #7 //得到报文头<span style="COLOR: #8 $headerSize = curl_getinfo($this-&ch, CURLINFO_HEADER_SIZE);<span style="COLOR: #9 $this-&info['header'] = substr($result, <span style="COLOR: #, $headerSize);<span style="COLOR: #0 //去掉报文头<span style="COLOR: #1 $result = substr($result, $headerSize);<span style="COLOR: #2 //得到所有包括服务器返回的信息<span style="COLOR: #3 $this-&info['after'] = curl_getinfo($this-&ch);<span style="COLOR: #4 //如果请求成功<span style="COLOR: #5 if($this-&errno() == <span style="COLOR: #){ //&& $this-&info['after']['http_code'] == 200<span style="COLOR: #6 return $result;<span style="COLOR: #7 }else{<span style="COLOR: #8 return false;<span style="COLOR: #9 }<span style="COLOR: #0 <span style="COLOR: #1 }<span style="COLOR: #2 <span style="COLOR: #3 /**<span style="COLOR: #4 * 返回解析后的URL,GET方式时会用到<span style="COLOR: #5 *<span style="COLOR: #6 * @param string $url :URL<span style="COLOR: #7 * @param array $params :加在URL后的参数<span style="COLOR: #8 * @return string<span style="COLOR: #9 */<span style="COLOR: #0 private function _parseUrl($url,$params)<span style="COLOR: #1 {<span style="COLOR: #2 $fieldStr = $this-&_parsmEncode($params);<span style="COLOR: #3 if($fieldStr){<span style="COLOR: #4 $url .= strstr($url,'?')===false ? '?' : '&';<span style="COLOR: #5 $url .= $fieldStr;<span style="COLOR: #6 }<span style="COLOR: #7 return $url;<span style="COLOR: #8 }<span style="COLOR: #9 <span style="COLOR: #0 /**<span style="COLOR: #1 * 对参数进行ENCODE编码<span style="COLOR: #2 *<span style="COLOR: #3 * @param array $params :参数<span style="COLOR: #4 * @param bool $isRetStr : true:以字符串返回 false:以数组返回<span style="COLOR: #5 * @return string || array<span style="COLOR: #6 */<span style="COLOR: #7 private function _parsmEncode($params,$isRetStr=true)<span style="COLOR: #8 {<span style="COLOR: #9 $fieldStr = '';<span style="COLOR: #0 $spr = '';<span style="COLOR: #1 $result = array();<span style="COLOR: #2 foreach($params as $key=&$value){<span style="COLOR: #3 $value = urlencode($value);<span style="COLOR: #4 $fieldStr .= $spr.$key .'='. $value;<span style="COLOR: #5 $spr = '&';<span style="COLOR: #6 $result[$key] = $value;<span style="COLOR: #7 }<span style="COLOR: #8 return $isRetStr ? $fieldStr : $result;<span style="COLOR: #9 }<span style="COLOR: #0 }
include(&class.curl.php&);$cu = new Curl();
//得到 baidu 的首页内容echo $cu-&get(&&);
//登录到QuickPHP实例中并且得到所有用户信息$cu-&post(&/code/qpdemo/?c=main&a=login&,array(&uname&=&&admin&,'upass&=&&admin&));echo $cu-&get(&/code/qpdemo&);
//向 http://a.com/a.php 上传内容和文件, a.php 的测试代码可以如下://&?php print_r($_POST);print_r($_FILES); /&echo $cu-&post(&http://a.com/a.php&,array(&id&=&1,&name&=&&yuanwei&),array(&img&=&&file/a.jpg&,'files&=&array(&file/1.zip&,'file/2.zip&)));
//得到所有调试信息echo &&br/&&,'ERRNO=&,$cu-&errno();echo &&br/&&,'ERROR=&,$cu-&error();echo &&pre&&.print_r($cu-&getinfo(),true).&&/pre&&;
以下为更多 CURL 的参数,来自网络收集:
PHP中的CURL函数库(Client URL Library Function)
curl_close & 关闭一个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_close & 关闭一个批处理句柄资源curl_multi_exec & 解析一个curl批处理句柄curl_multi_getcontent & 返回获取的输出的文本流curl_multi_info_read & 获取当前解析的curl的相关传输信息curl_multi_init & 初始化一个curl批处理句柄资源curl_multi_remove_handle & 移除curl批处理句柄资源中的某个句柄资源curl_multi_select & Get all the sockets associated with the cURL extension, which can then be &selected&curl_setopt_array & 以数组的形式为一个curl设置会话参数curl_setopt & 为一个curl设置会话参数curl_version & 获取curl相关的版本信息
curl_init()函数的作用初始化一个curl会话,curl_init()函数唯一的一个参数是可选的,表示一个url地址。curl_exec()函数的作用是执行一个curl会话,唯一的参数是curl_init()函数返回的句柄。curl_close()函数的作用是关闭一个curl会话,唯一的参数是curl_init()函数返回的句柄。
可选的常量包括:
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_SIZEheader部分的大小
CURLINFO_HEADER_OUT发送请求的字符串
CURLINFO_REQUEST_SIZE在HTTP请求中有问题的请求的大小
CURLINFO_SSL_VERIFYRESULTResult of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER
CURLINFO_CONTENT_LENGTH_DOWNLOAD从Content-Length: field中读取的下载内容长度
CURLINFO_CONTENT_LENGTH_UPLOAD上传内容大小的说明
CURLINFO_CONTENT_TYPE下载内容的&Content-type&值,NULL表示服务器没有发送有效的&Content-Type: header&
curl_setopt()函数的作用是为一个curl设置会话参数。curl_setopt_array()函数的作用是以数组的形式为一个curl设置会话参数。
可设置的参数有:
CURLOPT_AUTOREFERER自动设置header中的referer信息
CURLOPT_BINARYTRANSFER在启用CURLOPT_RETURNTRANSFER时候将获取数据返回
CURLOPT_COOKIESESSION启用时curl会仅仅传递一个session cookie,忽略其他的cookie,默认状况下curl会将所有的cookie返回给服务端。session cookie是指那些用来判断服务器端的session是否有效而存在的cookie。
CURLOPT_CRLF启用时将Unix的换行符转换成回车换行符。
CURLOPT_DNS_USE_GLOBAL_CACHE启用时会启用一个全局的DNS缓存,此项为线程安全的,并且默认为true。
CURLOPT_FAILONERROR显示HTTP状态码,默认行为是忽略编号小于等于400的HTTP信息
CURLOPT_FILETIME启用时会尝试修改远程文档中的信息。结果信息会通过curl_getinfo()函数的CURLINFO_FILETIME选项返回。
CURLOPT_FOLLOWLOCATION启用时会将服务器服务器返回的&Location:&放在header中递归的返回给服务器,使用CURLOPT_MAXREDIRS可以限定递归返回的数量。
CURLOPT_FORBID_REUSE在完成交互以后强迫断开连接,不能重用。
CURLOPT_FRESH_CONNECT强制获取一个新的连接,替代缓存中的连接。
CURLOPT_FTP_USE_EPRTTRUE to use EPRT (and LPRT) when doing active FTP downloads. Use FALSE to disable EPRT and LPRT and use PORT only.Added in PHP 5.0.0.
CURLOPT_FTP_USE_EPSVTRUE to first try an EPSV command for FTP transfers before reverting back to PASV. Set to FALSE to disable EPSV.
CURLOPT_FTPAPPENDTRUE to append to the remote file instead of overwriting it.
CURLOPT_FTPASCIIAn alias of CURLOPT_TRANSFERTEXT. Use that instead.
CURLOPT_FTPLISTONLYTRUE 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_VERIFYPEERFALSE 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 FALSE 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_TRANSFERTEXTTRUE to use ASCII mode for FTP transfers. For LDAP, it retrieves data in plain text instead of HTML. On Windows systems, it will not set STDOUT to binary mode.
CURLOPT_UNRESTRICTED_AUTH在使用CURLOPT_FOLLOWLOCATION产生的header中的多个locations中持续追加用户名和密码信息,即使域名已发生改变。
CURLOPT_UPLOAD启用时允许文件传输
CURLOPT_VERBOSE启用时会汇报所有的信息,存放在STDERR或指定的CURLOPT_STDERR中
CURLOPT_BUFFERSIZE每次获取的数据中读入缓存的大小,这个值每次都会被填满。
CURLOPT_CLOSEPOLICY不是CURLCLOSEPOLICY_LEAST_RECENTLY_USED就是CURLCLOSEPOLICY_OLDEST,还存在另外三个,但是curl暂时还不支持。.
CURLOPT_CONNECTTIMEOUT在发起连接前等待的时间,如果设置为0,则不等待。
CURLOPT_DNS_CACHE_TIMEOUT设置在内存中保存DNS信息的时间,默认为120秒。
CURLOPT_FTPSSLAUTHThe 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_TIMEThe number of seconds 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_CLOSEPOLICY决定应该停止哪些连接
CURLOPT_MAXREDIRS指定最多的HTTP重定向的数量,这个选项是和CURLOPT_FOLLOWLOCATION一起使用的。
CURLOPT_PORT一个可选的用来指定连接端口的量
CURLOPT_PROXYAUTHThe HTTP authentication method(s) to use for the proxy connection. Use the same bitmasks as described in CURLOPT_HTTPAUTH. For proxy authentication, only CURLAUTH_BASIC and CURLAUTH_NTLM are currently supported.
CURLOPT_PROXYPORTThe port number of the proxy to connect to. This port number can also be set in CURLOPT_PROXY.
CURLOPT_PROXYTYPEEither CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5.
CURLOPT_RESUME_FROM在恢复传输时传递一个字节偏移量(用来断点续传)
CURLOPT_SSL_VERIFYHOST1 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_SSLVERSIONThe SSL version (2 or 3) to use. By default PHP will try to determine this itself, although in some cases this must be set manually.
CURLOPT_TIMECONDITION如果在CURLOPT_TIMEVALUE指定的某个时间以后被编辑过,则使用CURL_TIMECOND_IFMODSINCE返回页面,如果没有被修改过,并且CURLOPT_HEADER为true,则返回一个&304 Not Modified&的header,CURLOPT_HEADER为false,则使用CURL_TIMECOND_ISUNMODSINCE,默认值为 CURL_TIMECOND_IFMODSINCE
CURLOPT_TIMEOUT设置curl允许执行的最长秒数
CURLOPT_TIMEVALUE设置一个CURLOPT_TIMECONDITION使用的时间戳,在默认状态下使用的是CURL_TIMECOND_IFMODSINCE
CURLOPT_CAINFOThe name of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with CURLOPT_SSL_VERIFYPEER.
CURLOPT_CAPATHA directory that holds multiple CA certificates. Use this option alongside CURLOPT_SSL_VERIFYPEER.
CURLOPT_COOKIE设定HTTP请求中&Set-Cookie:&部分的内容。
CURLOPT_COOKIEFILE包含cookie信息的文件名称,这个cookie文件可以是Netscape格式或者HTTP风格的header信息。
CURLOPT_COOKIEJAR连接关闭以后,存放cookie信息的文件名称
CURLOPT_CUSTOMREQUESTA custom request method to use instead of &GET& or &HEAD& when doing a HTTP request. This is useful for doing &DELETE& or other, more obscure HTTP requests. Valid values are things like &GET&, &POST&, &CONNECT& 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 server supports the custom request method first.
CURLOPT_EGBSOCKETLike CURLOPT_RANDOM_FILE, except a filename to an Entropy Gathering Daemon socket.
CURLOPT_ENCODINGheader中&Accept-Encoding: &部分的内容,支持的编码格式为:&identity&,&deflate&,&gzip&。如果设置为空字符串,则表示支持所有的编码格式
CURLOPT_FTPPORTThe value which will be used to get the IP address to use for the FTP &POST& instruction. The &POST& instruction tells the remote server 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 use the systems default IP address.
CURLOPT_INTERFACE在外部网络接口中使用的名称,可以是一个接口名,IP或者主机名。
CURLOPT_KRB4LEVELKRB4(Kerberos 4)安全级别的设置,可以是一下几个值之一:&clear&,&safe&,&confidential&,&private&。默认的值为&private&,设置为null的时候表示禁用KRB4,现在KRB4安全仅能在FTP传输中使用。
CURLOPT_POSTFIELDS在HTTP中的&POST&操作。如果要传送一个文件,需要一个@开头的文件名
CURLOPT_PROXY设置通过的HTTP代理服务器
CURLOPT_PROXYUSERPWD连接到代理服务器的,格式为&[username]:[password]&的用户名和密码。
CURLOPT_RANDOM_FILE设定存放SSL用到的随机数种子的文件名称
CURLOPT_RANGE设置HTTP传输范围,可以用&X-Y&的形式设置一个传输区间,如果有多个HTTP传输,则使用逗号分隔多个值,形如:&X-Y,N-M&。
CURLOPT_REFERER设置header中&Referer: & 部分的值。
CURLOPT_SSL_CIPHER_LISTA list of ciphers to use for SSL. For example, RC4-SHA and TLSv1 are valid cipher lists.
CURLOPT_SSLCERT传递一个包含PEM格式证书的字符串。
CURLOPT_SSLCERTPASSWD传递一个包含使用CURLOPT_SSLCERT证书必需的密码。
CURLOPT_SSLCERTTYPEThe format of the certificate. Supported formats are &PEM& (default), &DER&, and &ENG&.
CURLOPT_SSLENGINEThe identifier for the crypto engine of the private SSL key specified in CURLOPT_SSLKEY.
CURLOPT_SSLENGINE_DEFAULTThe identifier for the crypto engine used for asymmetric crypto operations.
CURLOPT_SSLKEYThe name of a file containing a private SSL key.
CURLOPT_SSLKEYPASSWDThe secret password needed to use the private SSL key specified in CURLOPT_SSLKEY.Note: Since this option contains a sensitive password, remember to keep the PHP script it is contained within safe.
CURLOPT_SSLKEYTYPEThe 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_USERAGENT在HTTP请求中包含一个&user-agent&头的字符串。
CURLOPT_USERPWD传递一个连接中需要的用户名和密码,格式为:&[username]:[password]&。
CURLOPT_HTTP200ALIASES设置不再以error的形式来处理HTTP 200的响应,格式为一个数组。
CURLOPT_HTTPHEADER设置一个header中传输内容的数组。
CURLOPT_POSTQUOTEAn array of FTP commands to execute on the server after the FTP request has been performed.
CURLOPT_QUOTEAn array of FTP commands to execute on the server 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_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_close()函数的作用是关闭一个批处理句柄资源。
curl_multi_getcontent()函数的作用是在设置了CURLOPT_RETURNTRANSFER的情况下,返回获取的输出的文本流。
curl_multi_info_read()函数的作用是获取当前解析的curl的相关传输信息。
curl_multi_select()Get all the sockets associated with the cURL extension, which can then be &selected&
相关文章列表
评论总数:0 条 网友评论

我要回帖

更多关于 php curl 的文章

 

随机推荐