牛骨文教育服务平台(让学习变的简单)
博文笔记

curl_setopt

创建时间:2011-08-21 投稿人: 浏览次数:963

(PHP 4 >= 4.0.2, PHP 5)

curl_setopt — Set an option for a cURL transfer

Report a bug

reject note Description

bool curl_setopt ( resource $ch , int $option , mixed $value )

Sets an option on the given cURL session handle.

Report a bug

reject note Parameters

ch

A cURL handle returned by curl_init().

option

The CURLOPT_XXX option to set.

value

The value to be set on option.

value should be a bool for the following values of the option parameter:

Option Set value to Notes
CURLOPT_AUTOREFERER TRUE to automatically set the Referer: field in requests where it follows a Location: redirect.  
CURLOPT_BINARYTRANSFER TRUE to return the raw output when CURLOPT_RETURNTRANSFERis used.  
CURLOPT_COOKIESESSION TRUE to mark this as a new cookie "session". It will force libcurl to ignore all cookies it is about to load that are "session cookies" from the previous session. By default, libcurl always stores and loads all cookies, independent if they are session cookies or not. Session cookies are cookies without expiry date and they are meant to be alive and existing for this "session" only.  
CURLOPT_CERTINFO TRUE to output SSL certification information to STDERR on secure transfers. Available since PHP 5.3.2. RequiresCURLOPT_VERBOSEto be on to have an effect.
CURLOPT_CRLF TRUE to convert Unix newlines to CRLF newlines on transfers.  
CURLOPT_DNS_USE_GLOBAL_CACHE TRUE to use a global DNS cache. This option is not thread-safe and is enabled by default.  
CURLOPT_FAILONERROR TRUE to fail silently if the HTTP code returned is greater than or equal to 400. The default behavior is to return the page normally, ignoring the code.  
CURLOPT_FILETIME TRUE to attempt to retrieve the modification date of the remote document. This value can be retrieved using theCURLINFO_FILETIME option with curl_getinfo().  
CURLOPT_FOLLOWLOCATION TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unlessCURLOPT_MAXREDIRS is set).  
CURLOPT_FORBID_REUSE TRUE to force the connection to explicitly close when it has finished processing, and not be pooled for reuse.  
CURLOPT_FRESH_CONNECT TRUE to force the use of a new connection instead of a cached one.  
CURLOPT_FTP_USE_EPRT TRUE to use EPRT (and LPRT) when doing active FTP downloads. Use FALSE to disable EPRT and LPRT and use PORT only.  
CURLOPT_FTP_USE_EPSV TRUE to first try an EPSV command for FTP transfers before reverting back to PASV. Set to FALSE to disable EPSV.  
CURLOPT_FTPAPPEND TRUE to append to the remote file instead of overwriting it.  
CURLOPT_FTPASCII An alias of CURLOPT_TRANSFERTEXT. Use that instead.  
CURLOPT_FTPLISTONLY TRUE to only list the names of an FTP directory.  
CURLOPT_HEADER TRUE to include the header in the output.  
CURLINFO_HEADER_OUT TRUE to track the handle"s request string. Available since PHP 5.1.3. TheCURLINFO_ prefix is intentional.
CURLOPT_HTTPGET TRUE to reset the HTTP request method to GET. Since GET is the default, this is only necessary if the request method has been changed.  
CURLOPT_HTTPPROXYTUNNEL TRUE to tunnel through a given HTTP proxy.  
CURLOPT_MUTE TRUE to be completely silent with regards to the cURL functions.  
CURLOPT_NETRC TRUE to scan the ~/.netrc file to find a username and password for the remote site that a connection is being established with.  
CURLOPT_NOBODY TRUE to exclude the body from the output. Request method is then set to HEAD. Changing this to FALSE does not change it to GET.  
CURLOPT_NOPROGRESS

TRUE to disable the progress meter for cURL transfers.

Note:

PHP automatically sets this option to TRUE, this should only be changed for debugging purposes.

 
CURLOPT_NOSIGNAL TRUE to ignore any cURL function that causes a signal to be sent to the PHP process. This is turned on by default in multi-threaded SAPIs so timeout options can still be used. Added in cURL 7.10.
CURLOPT_POST TRUE to do a regular HTTP POST. This POST is the normalapplication/x-www-form-urlencoded kind, most commonly used by HTML forms.  
CURLOPT_PUT TRUE to HTTP PUT a file. The file to PUT must be set withCURLOPT_INFILE and CURLOPT_INFILESIZE.  
CURLOPT_RETURNTRANSFER TRUE to return the transfer as a string of the return value ofcurl_exec() instead of outputting it out directly.  
CURLOPT_SSL_VERIFYPEER FALSE to stop cURL from verifying the peer"s certificate. Alternate certificates to verify against can be specified with theCURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. CURLOPT_SSL_VERIFYHOSTmay also need to be TRUE or FALSE ifCURLOPT_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 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 TRUE to keep sending the username and password when following locations (using CURLOPT_FOLLOWLOCATION), even when the hostname has changed.  
CURLOPT_UPLOAD TRUE to prepare for an upload.  
CURLOPT_VERBOSE TRUE to output verbose information. Writes output to STDERR, or the file specified using CURLOPT_STDERR.  

value should be an integer for the following values of the option parameter:

Option Set value to Notes
CURLOPT_BUFFERSIZE The size of the buffer to use for each read. There is no guarantee this request will be fulfilled, however. Added in cURL 7.10.
CURLOPT_CLOSEPOLICY Either CURLCLOSEPOLICY_LEAST_RECENTLY_USED or CURLCLOSEPOLICY_OLDEST. There are three other CURLCLOSEPOLICY_ constants, but cURL does not support them yet.  
CURLOPT_CONNECTTIMEOUT The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.  
CURLOPT_CONNECTTIMEOUT_MS The number of milliseconds to wait while trying to connect. Use 0 to wait indefinitely. If libcurl is built to use the standard system name resolver, that portion of the connect will still use full-second resolution for timeouts with a minimum timeout allowed of one second. Added in cURL 7.16.2. Available since PHP 5.2.3.
CURLOPT_DNS_CACHE_TIMEOUT The number of seconds to keep DNS entries in memory. This option is set to 120 (2 minutes) by default.  
CURLOPT_FTPSSLAUTH The FTP authentication method (when is activated): CURLFTPAUTH_SSL(try SSL first), CURLFTPAUTH_TLS (try TLS first), orCURLFTPAUTH_DEFAULT (let cURL decide). Added in cURL 7.12.2.
CURLOPT_HTTP_VERSION CURL_HTTP_VERSION_NONE (default, lets CURL decide which version to use),CURL_HTTP_VERSION_1_0 (forces HTTP/1.0), or CURL_HTTP_VERSION_1_1(forces HTTP/1.1).  
CURLOPT_HTTPAUTH

The HTTP authentication method(s) to use. The options are:CURLAUTH_BASICCURLAUTH_DIGESTCURLAUTH_GSSNEGOTIATE,CURLAUTH_NTLMCURLAUTH_ANY, and CURLAUTH_ANYSAFE.

The bitwise | (or) operator can be used to combine more than one method. If this is done, cURL will poll the server to see what methods it supports and pick the best one.

CURLAUTH_ANY is an alias for CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM.

CURLAUTH_ANYSAFE is an alias for CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM.

 
CURLOPT_INFILESIZE The expected size, in bytes, of the file when uploading a file to a remote site. Note that using this option will not stop libcurl from sending more data, as exactly what is sent depends on CURLOPT_READFUNCTION.  
CURLOPT_LOW_SPEED_LIMIT The transfer speed, in bytes per second, that the transfer should be below during the count of CURLOPT_LOW_SPEED_TIME seconds before PHP considers the transfer too slow and aborts.  
CURLOPT_LOW_SPEED_TIME The number of seconds the transfer speed should be belowCURLOPT_LOW_SPEED_LIMIT before PHP considers the transfer too slow and aborts.  
CURLOPT_MAXCONNECTS The maximum amount of persistent connections that are allowed. When the limit is reached, CURLOPT_CLOSEPOLICY is used to determine which connection to close.  
CURLOPT_MAXREDIRS The maximum amount of HTTP redirections to follow. Use this option alongside CURLOPT_FOLLOWLOCATION.  
CURLOPT_PORT An alternative port number to connect to.  
CURLOPT_PROTOCOLS

Bitmask of CURLPROTO_* values. If used, this bitmask limits what protocols libcurl may use in the transfer. This allows you to have a libcurl built to support a wide range of protocols but still limit specific transfers to only be allowed to use a subset of them. By default libcurl will accept all protocols it supports. See also CURLOPT_REDIR_PROTOCOLS.

Valid protocol options are: CURLPROTO_HTTPCURLPROTO_HTTPS,CURLPROTO_FTPCURLPROTO_FTPSCURLPROTO_SCPCURLPROTO_SFTP,CURLPROTO_TELNETCURLPROTO_LDAPCURLPROTO_LDAPSCURLPROTO_DICT,CURLPROTO_FILECURLPROTO_TFTPCURLPROTO_ALL

Added in cURL 7.19.4.
CURLOPT_PROXYAUTH The 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. Added in cURL 7.10.7.
CURLOPT_PROXYPORT The port number of the proxy to connect to. This port number can also be set in CURLOPT_PROXY.  
CURLOPT_PROXYTYPE Either CURLPROXY_HTTP (default) or 
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。