As I move into some advance PHP stuff, I came across the cURL. Now some of you might not know what is cURL, so here’s a definition from the cURL Website.
curl is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP. Curl supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos…), file transfer resume, proxy tunneling and a busload of other useful tricks.
So, putting that aside, basically, cURL is used(in PHP as I know it of) for behind the scenes communication between two webservers, something like webservices, but not webservices. Basically you POST the data(like in a form) to another webserver and GET the data returned by that server, its simply uses HTTP headers(usually) but you can use FTP etc. with it as well.
Now, that was somewhat basic intro to what cURL is, I don’t think its all correct but it somewhat paints the picture of what cURL is about, its just like Microsoft.XMLHTTP in ASP. Like if we need to post some data to a page & get some data in return, we do something like this in ASP
[asp]
Dim oMsXML, strResponse
Set oMsXML = Server.CreateObject(“Microsoft.XMLHTTP”)
oMsXML.Open “POST”, “http://www.example.com/public”, False
oMsXML.Send “id=14&start=1&end=50&repeat=false”
‘ get the response from the other server
strResponse = oMsXML.ResponseText
‘ release the XMLHTTP object
Set oMsXML = Nothing
[/asp]
Now, its almost same in PHP, I mean the concept is same!!
[php]
$oCURL = curl_init(“http://www.example.com/public”);
curl_setopt($oCURL, CURLOPT_HEADER, 0); // set this to 0 as we don’t need header info from the response
curl_setopt($oCURL, CURLOPT_RETURNTRANSFER, 1); // set as 1 because we need the response data in a variable
curl_setopt($oCURL, CURLOPT_POSTFIELDS, “id=14&start=1&end=50&repeat=false”); // use HTTP POST to send data
$strResponse = curl_exec($oCURL); //execute post and receive data
curl_close($oCURL); //close the cURL connection
[/php]
Now both of these codes do the same thing, they POST some data and then get the resultant data.
This is usually done for behind the scenes communication on a server to server level, as I said earlier, like on an eCommerce website, where you enter your Credit Card info and the website interacts with the card processor’s server and process the transaction.
Ok, enough of the intro and background info. Coming back to the topic(as the post title suggests), I was pretty much frustrated when the cURL extension of PHP didn’t load after I uncommented its entry in the php.ini file and restarted the server, Windows2000+/IIS5+
After a bit of searching around, I found a solution for Apache on Windows, tried it with some modification and it worked. So here it is(incase I forget again).
- uncomment the line in your php.ini where it says php_curl.dll and save the file
- copy php4ts.dll and libeay32.dll, ssleay32.dll(these last two found in the “dlls” directory of your PHP directory) to the WINNT(Windows 2000)/Windows(WindowsXP and 2003) directory
- restart IIS(you might’ve to restart windows if you are on Windows 2000 or if you don’t have php.ini path specified in the registry)
Now the cURL extension will run smooth as butter!! This is assuming that you’ve PHP4 installed as an ISAPI with IIS and that you installed it manually instead of using an installer.
So you might benefit from this post if you are trying to use cURL on Windows/IIS but have been failing to load the extension.
I’m now going to run some scripts and test this!! π
This was the only fix I found that worked. Thanks
yeah, I posted this after getting it to work myself!! π
you are welcome!! π
Thanks this fixed me right up.
Hi, I dont mean to sound dumb but i’ve got the Apache server 2.0.58 and PHP 5.1.4 installed on my computer and can’t get cURL to work. I removed the semi-colon before the line with php_curl.dll in the php.ini file and saved, then restarted Apache, still no luck. Do I need to restart my computer or install something else? Thanks for any reply.
Yeah, you’ll need to restart your Windows!! π
Thanks for the reply, but are you sure I can just change the php.ini file and there’s nothing else to install? I still get this when trying to run a script with curl in it: Call to undefined function curl_init().
Ok, now i reinstalled and dont get that error, but a blank page. Any ideas? thanks.
Curl is working successfully after following the steps given above.But one extra thing I did was i included php_curl.dll in extensions directory and in php.ini file igave extensions_dir=”c:phpextensions”.After that it is working fine.Thanks.
Priya, the curl library was already there in the extensions directory of my PHP directory, so I didn’t need to put it there!! π
I can’t get this no matter what i do..
manually installed php 5.2.5 on a iis server and the installation works fine..
i went to add curl..heres all i did.. somes redundant but desperation
1 uncommented php_curl.dll in php.ini
2 changed path system enviroment variables to include c:php
3 set ext directory to c:phpext, also tried ./ and .ext
4 copied ssleay32.dll, libeay32.dll,php5ts.dll to system 32
5 copied php_curl.dll to c:php, system32
6. restarted the server lots
7. checked dll version of curl to php version is a match 5.2.5
im out of ideas.. everyone seems to say it works by doing half the stuff ive done.. all i get is fatal error call to undefined function
phpinfo reads ctype enabled.. under that it should say curl but it doesn’t
@Shadix:
What version of Windows are you using? If its WindowsXP then you need to put the files in “System” folder instead of “System32”.
I resolved this problem.. most unusual.. it seems the trouble was that php would read php.ini but ignored all the data inside the file unless i placed the file in the directory it wanted.. on phpinfo this directory was c:windows it definately would read php.ini though becuase if i doubled up on the files i would get the alias error no input file
So your php.ini file was not being considered by Windows. Ofcourse it needs to be in system path, so either you do it by adding to the system environment variable or simply by putting it in a windows folder like “windows” or “system”. π
Just in case it helps anyone. I had exactly the same problem and it was a permissions issue on IIS. Just needed to change the permissions of the dll and it worked.
Nice dude – finally got CURL running on php 5.2.6, windows Vista and Apache 2.2 after 3 hours of surfing and dubugging.
I basically copied php.ini, php5ts.dll, libeay32.dll, php_curl.dll, and ssleay32.dll into
c:php
c:phpext
c:windows
c:windowssystem
c:windowssystem32
and ONE of them did the trick lol.
ugh, I’ve been struggling to get this to work… on XP just tried everything you all said… after copying the files over to c:windowssystem32, system, apache is crashing on me now. even after a reboot.
Seriously why can’t PHP come with all this crap pre-installed, like PEAR and PECL too its ridiculous. They really need to set a standard somewhere.
I suggest that you get XAMPP if you are having trouble installing this. π
for a windows server running IIS and php5:
if curl does not work once php.ini is set up right (to include the php_curl.dll and you have restarted IIS since editing it), it is probably the curl dependencies.
this happened to me and my solution was to copy libeay32.dll and ssleay32.dll in to the system32 directory then restart IIS.
btw thanks for the thread!
@IISnoob:
Yup, I’ve mentioned that in step #2 above! π
Thank you,
This is working.
The other treads don’t tell if to copy the 3 dll, even in PHP 5.02 have to copy it first.
Thank you, it cost me hours to know that dlls have to be copied. Once again thank you,
Sincerely yours,
Luckman Raharja