Jump to content

[SOLVED] problem with curl_init() -- fatal error!!


stevieontario

Recommended Posts

Morning php Freaks:

 

I'm playing in a sandbox (xampp) and testing some code (php 5.2.8) containing the function curl_init.

 

A very rudimentary version of my web app is running, successfully, using curl_init() at one point.

 

But when I test my code in my test environment using the identical function, I get the following error:

 

Fatal error: Call to undefined function curl_init() in C:\Program Files\xampp\htdocs\dev\Functions1.php on line 100

 

Anybody have any ideas what's going on?

 

Thanks!

Link to comment
Share on other sites

Thanks maq. Here's the relevant code:

 

function curl_string($url,$user_agent,$proxy=0)
{
       $ch = curl_init();
       //curl_setopt ($ch, CURLOPT_PROXY, $proxy);
       curl_setopt ($ch, CURLOPT_URL, $url);
       curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
       curl_setopt ($ch, CURLOPT_HEADER, 0);
       curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
       $result = curl_exec ($ch);
       curl_close($ch);
       return $result;
}

Link to comment
Share on other sites

Looks right to me, did you have the library installed, like Ben said?

 

Here's how you can check:

 

This probably means the cURL library is not installed. If you run a page with just this in:

 

php_info();
?>

 

You'll be able to verify this. If you cannot find a section called curl/libcurl, then it is not installed.

Link to comment
Share on other sites

Like redarrow says, cURL isn't loaded/enabled on the server. To enable it, stop the server via the XAMPP control panel, then open the relevant php.ini file (mine's located in XAMPP/apache/bin/php.ini), and remove the semi-colon appearing before extension=php_curl.dll (around halfway through the file). Start your server again, and it should work.

Link to comment
Share on other sites

thanks badbad and everyone else,

 

I'm not a Windows expert, and I suspect the following subsequent problem has to do with Windows.

 

I "found" the file you refer to (xampp/apache/bin/php.ini) but not by navigating to the folder. When I navigated to the folder I couldn't see a file called "php.ini" or any text file called "php."

 

Rather, I "found" php.ini it using the Windows search feature, which indicated that php.ini is in the referenced folder.

 

I also found the relevant line and made the recommended change. But couldn't save it (I guess Search puts everything into a temp folder). So I just navigated to xampp/apache/bin and saved it from Notepad. This created a new file (i.e., didn't overwrite the existing one). So the code still won't execute.

Link to comment
Share on other sites

Strange that you can't see the file. Maybe it's hidden? But it's not on my machine (running Vista). And I can't see why you shouldn't be able to edit the one you found through a search (I'm perfectly able to).

 

It could also be that the server is using another php.ini file (there are several within the XAMPP folder; I once had a hard time finding the relevant one) - in that case you could try to edit all the php.ini files you can find, and see if it works. Apache must be using one of them :)

 

Also: What do you mean you "couldn't save it"?

Link to comment
Share on other sites

badbad,

 

Actually, the message says I cannot "create" the file. I found more than one "php.ini" when I did a search, and was able to make your recommended change and save it. But there are two others whose search results do not indicate a path beginning with "C://". I cannot save those two others; I get the message:

 

Cannot create the C:// etc temporary directory. Weirdness!

 

I tried attaching a screenshot showing the error message, but it got rejected.

Link to comment
Share on other sites

Ah, documentation, clever idea ;)

 

It says XAMPP/apache/bin/php.ini is the right file, so you should be able to find it. Have you turned on the setting to display hidden files? Not that it should be hidden though. Maybe you need administrative rights to edit the file - try running Notepad as administrator (if you're using Vista).

 

Edit: And remember to restart the Apache server after editing the file.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.