Fatal error curl_reset() undefined why? - php

I am using curl to request another site for getting data. My code having curl_reset() funciton is working well at localhost, but when i have updated my code to server. Its giving error
Fatal error: Call to undefined function curl_reset() in
/data/html/reviewkiller1.0/controller/searchController.php on line
2054
Note: I have checked for curl extension it is enabled.
Why it is so???

Requires no PHP version updating.
if (!function_exists('curl_reset'))
{
function curl_reset(&$ch)
{
$ch = curl_init();
}
}

PHP is old on your server.
From the manual: (PHP 5 >= 5.5.0)

My PHP version is 5.3 so i was not able to use curl_reset() function.
Solution
I was using curl_reset() function for getting response of multiple curl request.
So i have removed curl_reset() and used
curl_setopt($curl_handle, CURLOPT_HTTPGET, 1);
curl_setopt($curl_handle, CURLOPT_POST, false);
Problem was after post request my get request was not giving response when i have set curl_post to false to my request it works well.
Conclusion: Its important keep calling setopt to switch between GET and POST request when you are using multiple curl request.

Here is the solution tested 100% working:
Error from php-error-log due to using curl_reset with php version 5.4:
Fatal error: Call to undefined function GuzzleHttp\Handler\curl_reset() in ...
Upgrade to php version 5.5 successfully resolved issue. If you are on cpanel upgrading php version takes only 3 or 4 clicks.
enjoy!
Please mark as answered if it resolve the issue. Thanks!

Related

Why does curl error after version update?

After update version of ci 3.1.1 & php 7.3 there is a error in curl call using rest library in codeingiter
error like : 45bind failed with errno 10014: Bad argument
i make a manual call using curl working perfect but using curl library there is a error like above. any solutions?

file_get_contents() returning empty string

I am having the weirdest, head splitting issue ever. The real issue is I'm getting a SOAP error SOAP-ERROR: Parsing WSDL: Couldn't load from 'some website' : failed to load external entity
In the past it was caused by the host not responding, bad URL, etc. But today I have no problem connecting to the host.
I'm using Symfony to run the API. I stripped ALL of the soap code from the API, created a simple test.php file and ran it from the command line on the exact server the API is running on, and it worked perfectly!
So I went back to the Symfony, flushed the cache. Still not working.
Next I decided to test the simplest methods I could and slapped 'file_get_contents('the url to the WSDL')` at the very top of the service that's making this SOAP call. It returns an empty string. No errors in the error log.
Next I tried moving that to the Controller. Still an empty string.
I tried file_get_contents('https://google.com'). Still, empty string no matter where in the Controller or Service I stick it. But, if on that same server I run a PHP script from the command line, it works no problem.
I don't even know where to begin showing you my code. Because it doesn't matter if file_get_contents() is in the controller, an entity, or the services it's using. Every time it returns an empty string.
As a side note, this is a development server. Which is an exact mirror of production (they just made an image of the production server). The whole API works fine in production and also on my local dev environment and in other environments it's been deployed to. So I'm entirely lost on why it's just this server, and just this particular application.
Any help is appreciated.
==
Update 1
As suggested by a friend I checked allow_url_fopen in both the cli php -i and apache phpinfo() and in both cases it's set to On
==
Update 2
As Pedro suggested I ran a cURL test in the controller of the API. And that worked, it retrieved the contents of the WDSL, and of course Google.
However, it doesn't solve my root problem with SOAP not retrieving the contents of a URL. Nor the obvious file_get_contents() not working. Does the PHP SOAP client use file_get_contents() to retrieve WSDLs?
==
Update 3
For those curious this is where the code is failing. I have to omit a lot of the class because it contains information specific to my company.
<?php
class Carrier implements CarrierInterface
{
//...omitted code
private function getSoapClient($wsdl)
{
// This line is what fails.
return new \SoapClient( $wsdl , array('trace' => true));
}
//...omitted code
public function quote(QuoteInterface $quote)
{
//Get the Soap Client
$client = $this->getSoapClient($this->quoteWSDL);
// The rest of the SOAP CALL
return $quote;
}
}
But in short, $this->quoteWSDL is just a URL, and yes it has a the correct value I've checked. But it fails when trying to construct the SOAP client stating SOAP-ERROR: Parsing WSDL: Couldn't load from '<url>' : failed to load external entity
==
Update 4 (with Kinda Solution)
Restarting apache fixed everything. I'm not sure why I didn't just ask the SysAdmin to do that sooner. That's like IT 101 right there. Thanks for your help. But now I'm curious why this was an issue to begin with. Weird.
My guess is that allow_url_fopen is disabled.
To enable it, you'll have to set allow_url_fopen=1 on php.ini.
Restart the Apache server to reload the configuration.
Have you considered using curl? Here's an example:
$url = "http://google.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$contents = curl_exec($ch);
curl_close($ch);
PS: For future users: Make sure you read the comments below.

Error using curl_init() in php environment on BlueMix

I use the PHP runtime on Bluemix. In my solution, I need to invoke the external API available on the Internet on port 3000.
I used curl to manage the API invocation using the following code:
$endPoint="http://".$this->server.":".$this->port.$endPoint;
$session = curl_init($endPoint);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($session);
In the Bluemix log I found the following error:
Got error 'PHP message: PHP Fatal error: Call to undefined function
curl_init() in /home/vcap/app/htdocs/include/service.php on line 50\n',
referer: http://m2msite.mybluemix.net/login.php
It does not seem to be a defined curl library inside my runtime.
I do not found any documentation on how to define the curl library in a Bluemix runtime.
Can anyone help me to configure my runtime in a correct way?
Many thanks in advance
I found the solution.
under the project root I create a directory .bp-config
Inside the directory I create a file option.json with the following content:
{
"PHP_EXTENSIONS": ["mysqli","curl"]
}
mysqli for mysql library and curl for the curl library.
So now I am able to use curl library inside my project
Has anyone the link for a complete documentation around this configuration steps ?
Ciao
the complete documentation for your this kind of configuration related to a PHP buildpack could be found here
https://docs.cloudfoundry.org/buildpacks/php/gsg-php-config.html

Fatal error: Call to undefined function http_get()

I tried to make cross domain request in php coding using http_get. In my server, there is no required modules installed. I dont know what to install to make posible of doing http_get.
The error which i got was
Fatal error: Call to undefined function http_get() in
C:\xampp\htdocs\article\index.php on line 2
I tried to do so (PECL pecl_http >= 0.1.0)
http_get — Perform GET request
but, i did not find out solution.
So, please help me to run http_get coding. Thanks in advance.
I think that you have to enable extension=php_http.dll in your php.ini file and after that restart your Apache Server.
I advise you to use cURL instead of http_get() (same manipulation, you have to enable extension=php_curl.dll and restart apache)
Hope that Helps :)
To directly answer the question, you've to enable extension=php_http.dll in php.ini and restart apache, but there's absolutely no need to use http_get() in our days.
Here's 3 good alternatives:
The php curl library
file_get_contents()
copy()
Curl usage:
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://testcURL.com/?item1=value&item2=value2',
CURLOPT_USERAGENT => 'User Agent X'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);
file_get_content() usage:
$my_var = file_get_contents("https://site/");
copy() usage:
copy("https://site/image.png", "/local/image.png");

PHP - Call to undefined function http_inflate()

i am trying to create a module that makes a call to the stackexchange API which returns a gzipencoded or a deflated Json response. to decompress it i am using the method http_inflate but i am getting the following error:
Fatal error: Call to undefined function http_inflate()
Is this method dependent on any library or extension?
I am running PHP 5.3.13
http_inflate is not bundled with PHP. It is part of the HTTP library. See this page for instructions on how to install it.
You need to install the HTTP extension, as seen in the link below:
PHP.net: Installing the HTTP plugin
You need to install an extension (pecl_http). See here on php.net for information.

Categories