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
Related
i would like to know what causes the error:
Could not access remote resource https://repositories.typo3.org/mirrors.xml.gz.
by trying to download a extension in extension manager.
All configuration:
[SYS][curlUse] = 1
Seems to depend on my system because version 6.2 and 7.6.4 having same error. I am using Xampp on mac os. Their server is not down because i can call https://repositories.typo3.org/mirrors.xml.gz with browser.
Anyone knows how to solve that?
Adding the line
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); directly after
$ch = curl_init(); in curl.php and adding same line next to the other curl_setopt( ... ) in GeneralUtility.php solved this issue for typo3 7.6.4. thanks for your hints. Able to add extensions now.
I have been using this PHP class to upload images to S3. Here's an example code:
$s3 = new S3($awsAccessKey,$awsSecretKey);
$s3upload= $s3->putObject(
$s3->inputFIle($tmp_name, false),
$s3BucketName,
$filename,
S3::ACL_PUBLIC_READ
);
Out of nowhere I have been getting this error today:
Warning</b>: S3::putObject(): [7] Failed to connect to bucketName.s3.amazonaws.com port 80: No route to host in <b>/S3.php</b> on line <b>355
I have used the following script to check the curl settings, and I can get the whole google page, so there shouldn't be any problem with CURL
$ch = curl_init("http://google.com"); // initialize curl handle
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
print($data);
Anyone using that PHP class? Have you experienced this problem? How can I find out where the problem lays?
This can happen when some api calls get outdated. I would recommend using the official php libraries. They work almost the same way this library works, but they are being kept up-to-date by Amazon programmers.
I would recommend the official PHP library as well, it's well documented and works well.
No route to host might suggest network problems on your server.
Can you ping bucketName.s3.amazonaws.com from the server?
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");
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!
if I use Firefox and access http://svcs.ebay.com/services/search/FindingService/v1 I get some sort of XML in respose, when I do that through PHP I get Internal Server Error 500
$ php -r 'print_r(simplexml_load_file("http://svcs.ebay.com/services/search/FindingService/v1"));'
PHP Warning: simplexml_load_file(http://svcs.ebay.com/services/search/FindingService/v1): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
in Command line code on line 1
PHP Stack trace:
PHP 1. {main}() Command line code:0
PHP 2. simplexml_load_file() Command line code:1
PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://svcs.ebay.com/services/search/FindingService/v1" in Command line code on line 1
PHP Stack trace:
PHP 1. {main}() Command line code:0
PHP 2. simplexml_load_file() Command line code:1
$
When I visit http://svcs.ebay.com/services/search/FindingService/v1 in firefox, firebug reports that the HTTP reponse code is indeed 500. (even though it sends some XML in the request body)
You're calling the web service in the wrong way.
Yes, you got XML back, but the response code is 500, meaning your URL is wrong.
Calling ximlexml_load_file via url wrappers expects a success code.
That said, you could probably get at the data anyway. Maybe.
But you should figure out how the service wants you to to query.
If you want to be able to read 500 request data use curl
<?php
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://svcs.ebay.com/services/search/FindingService/v1");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// grab URL and pass it to the browser
$xml = curl_exec($ch);
$simpleXml = simplexml_load_string($xml);
// close cURL resource, and free up system resources
curl_close($ch);
?>
When I go to that site, I get:
<ms:errorMessage>
−
<error>
<errorId>2038</errorId>
<domain>SOA</domain>
<severity>Error</severity>
<category>System</category>
<message>Missing SOA operation name header</message>
</error>
</ms:errorMessage>
So it would seem that the URL is to a web service and probably requires some kind of authentication or at least input data in the request header. The HTTP response 500, according to Wikipedia, is a generic error meaning that the server can't specify the problem but knows there was one. Here's the best part of that article:
Response status codes beginning with
the digit "5" indicate cases in which
the server is aware that it has
encountered an error or is otherwise
incapable of performing the request.
Except when responding to a HEAD
request, the server should include an
entity containing an explanation of
the error situation, and indicate
whether it is a temporary or permanent
condition.
All that combined, I'd have to say your issue is that your are trying to grab a file from a remote server using a method that assumes you have some directory-level access to that file, and the server is responding with "Um, what?"
If you want to get the actual XML error as though you were in Firefox, use cURL:
$ebay_url = "http://svcs.ebay.com/services/search/FindingService/v1";
$ebay_page = curl_init();
curl_setopt($ebay_page, CURLOPT_RETURNTRANSFER, true); //output to string.
curl_setopt($ebay_page, CURLOPT_URL, $ebay_url); //set the url for the request.
$ebay_response = curl_exec($ebay_page);
print_r(simplexml_load_string($ebay_response));
If you want to actually get something back more meaningful, I would look at PHP's SoapClient methods and the actual ebay web service documentation.
The http headers need to be set specifying the operation to be executed. If you read how to make a call using the finding API, the article mentions the following http headers that need to be set:
X-EBAY-SOA-SERVICE-NAME: FindingService
X-EBAY-SOA-OPERATION-NAME: findItemsAdvanced <-- whatever call you are making
X-EBAY-SOA-SERVICE-VERSION: 1.0.0
X-EBAY-SOA-GLOBAL-ID: EBAY-US
X-EBAY-SOA-SECURITY-APPNAME: MyAppID
X-EBAY-SOA-REQUEST-DATA-FORMAT: XML
X-EBAY-SOA-MESSAGE-PROTOCOL: XML
Once those are set your call shoud work fine.
Maybe you want to try the following URL. When I do, I get back the XML and a 200 response.
http://svcs.ebay.com/services/search/FindingService/v1?wsdl
You need to reinstall your php (assuming you already have apache2 installed). Using these commands:
1) sudo apt update && apt upgrade
2) sudo apt install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php
3) sudo service apache2 restart