cURL Options
PHP has a built-in implementation of cURL that is real nice. But it's format is completely difference than using cURL through the command line. This guide takes the options list from PHP.net, and attempts to match each option up with it's command line counterpart, from cURL's man page. This will save you tons of time if you are converting scripts that use the command line cURL, to scripts that use PHP's native cURL.
For more info on using PHP's cURL implementation, check out php.net
For the full, original list of PHP's cURL options, check out the curl_setopt( ) function
Boolean Options
CLI Flag | curl_setopt( ) | Description |
---|---|---|
-e/--referer "<url>;auto" | CURLOPT_AUTOREFERER | TRUE to automatically set the http referer header when following a redirect |
-j/--junk-session-cookies | CURLOPT_COOKIESESSION | TRUE to discard all session cookies, to initiate a new session |
--crlf | CURLOPT_CRLF | TRUE to convert Unix newlines to CRLF newlines on transfers |
-f/--fail | CURLOPT_FAILONERROR | TRUE to fail silently on HTTP errors |
-i/--include* | CURLOPT_FILETIME | TRUE to get modification date of file. *-i returns the full HTTP header, including the modification date. |
-L/--location | CURLOPT_FOLLOWLOCATION | TRUE to follow any Location headers sent by server |
--disable-eprt | CURLOPT_FTP_USE_EPRT | TRUE to use EPRT, FALSE to disable EPRT |
--disable-epsv | CURLOPT_FTP_USE_EPSV | TRUE to use EPSV, FALSE to disable EPSV |
-a/--append | CURLOPT_FTPAPPEND | TRUE to append to a file instead of overwriting it. |
-l/--list-only | CURLOPT_FTPLISTONLY | TRUE to only list the names of an FTP directory |
-i/--include | CURLOPT_HEADER | TRUE to include the header in the output |
-G/--get | CURLOPT_HTTPGET | TRUE to reset the HTTP request method to GET |
-p/--proxytunnel | CURLOPT_HTTPPROXYTUNNEL | TRUE to tunnel through a given HTTP proxy |
-s/--silent | CURLOPT_MUTE | TRUE to be completely silent with regards to the cURL functions |
-n/--netrc | 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 |
-I/--head | CURLOPT_NOBODY | TRUE to exclude the body from the output. Request method is then set to HEAD. |
-X/--request POST | CURLOPT_POST | TRUE to do a regular HTTP POST |
-T/--upload-file <file> | CURLOPT_PUT | TRUE to HTTP PUT a file. The file to PUT must be set with CURLOPT_INFILE and CURLOPT_INFILESIZE |
-k/--insecure | CURLOPT_SSL_VERIFYPEER | FALSE to stop cURL from verifying the peer's certificate |
-B/--use-ascii | CURLOPT_TRANSFERTEXT | TRUE to use ASCII mode for FTP transfers |
--location-trusted | CURLOPT_UNRESTRICTED_AUTH | TRUE to keep sending the username and password when following locations |
-v/--verbose | CURLOPT_VERBOSE | TRUE to output verbose information |
Integer Options
CLI Flag | curl_setopt( ) | Description |
---|---|---|
--connect-timeout <#> | CURLOPT_CONNECTTIMEOUT | The number of seconds to wait while trying to connect. Use 0 to wait indefinitely |
-0/--http1.0 | CURLOPT_HTTP_VERSION | Which HTTP version to use, constants: CURL_HTTP_VERSION_NONE, CURL_HTTP_VERSION_1_0, CURL_HTTP_VERSION_1_1 |
--anyauth --basic --digest --ntlm --krb <level> |
CURLOPT_HTTPAUTH | The HTTP authentication method(s) to use: CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, CURLAUTH_NTLM, CURLAUTH_ANY, CURLAUTH_ANYSAFE |
-Y/--speed-limit <speed> | 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 |
-y/--speed-time <time> | CURLOPT_LOW_SPEED_TIME | The number of seconds the transfer speed should be below CURLOPT_LOW_SPEED_LIMIT before PHP considers the transfer too slow and aborts |
--max-redirs <num> | CURLOPT_MAXREDIRS | The maximum amount of HTTP redirections to follow |
--proxy-anyauth --proxy-basic --proxy-ntlm |
CURLOPT_PROXYAUTH | The HTTP authentication method(s) to use for the proxy connection |
-x/--proxy <proxyhost[:port]> | CURLOPT_PROXYPORT | The port number of the proxy to connect to |
-C/--continue-at <offset> | CURLOPT_RESUME_FROM | The offset, in bytes, to resume a transfer from |
-2/--sslv2 -3/--sslv3 |
CURLOPT_SSLVERSION | The SSL version (2 or 3) to use |
-m/--max-time <seconds> | CURLOPT_TIMEOUT | The maximum number of seconds to allow cURL functions to execute |
--limit-rate <speed> | CURLOPT_MAX_RECV_SPEED_LARGE CURLOPT_MAX_SEND_SPEED_LARGE |
If a transfer exceeds this speed (counted in bytes per second) on cumulative average during the transfer, the transfer will pause to keep the average rate less than or equal to the parameter value |
String Options
CLI Flag | curl_setopt( ) | Description |
---|---|---|
--cacert <CA certificate> | CURLOPT_CAINFO | The name of a file holding one or more certificates to verify the peer with |
--capath <CA certificate directory> | CURLOPT_CAPATH | A directory that holds multiple CA certificates |
-b/--cookie <name=data> | CURLOPT_COOKIE | The contents of the "Cookie: " header to be used in the HTTP request |
-b/--cookie <file> | CURLOPT_COOKIEFILE | The name of the file containing the cookie data |
-c/--cookie-jar <file> | CURLOPT_COOKIEJAR | The name of a file to save all internal cookies to when the handle is closed |
-X/--request <command> | CURLOPT_CUSTOMREQUEST | A custom request method to use instead of "GET" or "HEAD" when doing a HTTP request |
--egd-file <file> | CURLOPT_EGDSOCKET | A filename to an Entropy Gathering Daemon socket |
-H/--header "Accept-Encoding: gzip,deflate" | CURLOPT_ENCODING | The contents of the "Accept-Encoding: " header. This enables decoding of the response. |
-P/--ftp-port <address> | CURLOPT_FTPPORT | The 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 |
--interface <name> | CURLOPT_INTERFACE | The name of the outgoing network interface to use. This can be an interface name, an IP address or a host name |
--krb <level> | CURLOPT_KRB4LEVEL | The Kerberos 4 security level. Any of the following values (in order from least to most powerful) are valid: "clear", "safe", "confidential", "private" |
-d/--data <data> | CURLOPT_POSTFIELDS | The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path. The filetype can be explicitly specified by following the filename with the type in the format ';type=mimetype'. This parameter can either be passed as a urlencoded string like 'para1=val1¶2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data. As of PHP 5.2.0, value must be an array if files are passed to this option with the @ prefix. |
-x/--proxy <proxyhost[:port]> | CURLOPT_PROXY | The HTTP proxy to tunnel requests through |
-U/--proxy-user <user:password> | CURLOPT_PROXYUSERPWD | A username and password formatted as "[username]:[password]" to use for the connection to the proxy |
--random-file <file> | CURLOPT_RANDOM_FILE | A filename to be used to seed the random number generator for SSL |
-r/--range <range> | CURLOPT_RANGE | Range(s) of data to retrieve in the format "X-Y" where X or Y are optional. HTTP transfers also support several intervals, separated with commas in the format "X-Y,N-M" |
-e/--referer <URL> | CURLOPT_REFERER | The contents of the "Referer: " header to be used in a HTTP request |
--ciphers <list of ciphers> | CURLOPT_SSL_CIPHER_LIST | A list of ciphers to use for SSL. For example, RC4-SHA and TLSv1 are valid cipher lists |
-E/--cert <certificate[:password]> | CURLOPT_SSLCERT | The name of a file containing a PEM formatted certificate |
-E/--cert <certificate[:password]> | CURLOPT_SSLCERTPASSWD | The password required to use the CURLOPT_SSLCERT certificate |
--cert-type <type> | CURLOPT_SSLCERTTYPE | The format of the certificate. Supported formats are "PEM" (default), "DER", and "ENG" |
--engine <name> | CURLOPT_SSLENGINE | The identifier for the crypto engine of the private SSL key specified in CURLOPT_SSLKEY |
--key <key> | CURLOPT_SSLKEY | The name of a file containing a private SSL key |
--pass <phrase> | CURLOPT_SSLKEYPASSWD | The secret password needed to use the private SSL key specified in CURLOPT_SSLKEY |
--key-type <type> | CURLOPT_SSLKEYTYPE | The key type of the private SSL key specified in CURLOPT_SSLKEY. Supported key types are "PEM" (default), "DER", and "ENG" |
-A/--user-agent <agent> | CURLOPT_USERAGENT | The contents of the "User-Agent: " header to be used in a HTTP request |
-u/--user <user:password> | CURLOPT_USERPWD | A username and password formatted as "[username]:[password]" to use for the connection |