Parameters

Return Values

Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER
option is set, it will return
the result on success, FALSE on failure.

Warning

This function may
return Boolean FALSE, but may also return a non-Boolean value which
evaluates to FALSE. Please read the section on Booleans for more
information. Use the ===
operator for testing the return value of this
function.

Don't disable SSL verification! You don't need to, and it's super easy to stay secure! If you found that turning off "CURLOPT_SSL_VERIFYHOST" and "CURLOPT_SSL_VERIFYPEER" solved your problem, odds are you're just on a Windows box. Takes 2 min to solve the problem. Walkthrough here:

Just a simple curl_exec() example with a twist: I use the familiar http response status code returned from curl_getinfo() to put either data, or a custom error message + curl_error() into a single string. I find this useful when the response ends up in a <div> or <span> tag.

Be careful when using curl_exec() and the CURLOPT_RETURNTRANSFER option. According to the manual and assorted documentation:Set CURLOPT_RETURNTRANSFER to TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.

When retrieving a document with no content (ie. 0 byte file), curl_exec() will return bool(true), not an empty string. I've not seen any mention of this in the manual.

CURL automatically creates the host parameter (since it is required for HTTP/1.1 requests), so you don't need to set it. But if you created a custom host parameter, the above bug would cause a '400 Bad Request' response due to invalid host specified.

Also when copying and pasting the class code, make sure that no line breaks occur (for example in the $header and $user_agent definitions etc.). It will still be valid PHP, but the HTTP request will not be valid, and you may get a '400 Bad Request' response from the server.

It took me a little playing around with an HTTP Sniffer before I finally got an HTTP POST request fully working!

fyi - if you are having problems getting a
webpage to display in your webpage with
curl_setopt(CURLOPT_RETURNTRANSFER, 1);
due to version bugginess perhaps,
you may can use output control functions
like this to show a web page
inside your webpage:

Be always aware that CURLOPT_SSL_VERIFYPEER set to FALSE or 0 should never be used for production as it makes the link inmediately vulnerable to man-in-the-middle attack, still you can use it during development, but I would suggest that only if you KNOW what are you doing, otherwise spend some more time making requests to HTTPS sites work without resorting to set that option to FALSE or 0.

/* To quote curl_errno documentation: Returns the error number for the last cURL operation on the resource ch, or 0 (zero) if no error occurred. */if (curl_errno($creq)) { print curl_error($creq);} else {curl_close($creq);}?>

The data part (e.g. "This is a string") inside the 3rd parameter should be applied with urlencode()

Otherwise, if you intend to send a string like "%2F", you will end up with a "/" on the receiving end, which can cause troubles. (e.g. serialize() data cannot be unserialize() becase of the change in string length).

If you retrieve a web page and print it (so you can see it in your browser), and the page has an expiration, this expiration now applies to MyProgram.php and next time your program/page is called, even if it's grabbing a different web page, it will show what it just displayed. In Netscape you can get rid of this by going into Edit, Options, Advanced, Cache, and clear out the Disk Cache. But this is really annoying after short order. The following prevents the above scenario:

I was having a problem, for almost a week, of curl_exec() freezing/hanging when I made a request with it to a page that spends over an hour converting a large video file, and only afterwards sends control-data back to the calling script.

On Fri, Feb 11, 2011 at 1:32 PM, Daniel Stenberg <daniel-of-haxx.se> wrote:> On Fri, 11 Feb 2011, Tolas Anon wrote:>>>> It is also very easy for an application to enable the options as I've>>> shown.>>>> Just not for the platforms i use, apparently.. :(>> Why not? A quick search for "tcp keepalive windows" shows this:> http://msdn.microsoft.com/en-us/library/ms819735.aspx

This fixed my problem in the simple test AND in my application!No need to send keep-alive bytes on the text/html level either.

I just added the "KeepAliveTime" setting with windows 7 regedit.exe inHKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/services/Tcpip, as aREG_DWORD value, set it to decimal 25000 (so 25 seconds), rebooted,and it all works as i want it now..

Note that windows registry entries key names are case-sensitive, wrongcasing and they'll be deleted on restart.