My curl request is..
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
//curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_INTERFACE,$proxy);
curl_setopt($ch,CURLOPT_PORT, '8888');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
pr($ch);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
Error Resource id #12
i am trying to fetch data from amazon and have a list of ip address, and port number.
sending request from diff port number preventing blocking from amazon...
It seems that your curl client is getting some response from server that it can not understand, Error#12 means: CURLE_FTP_WEIRD_USER_REPLY
here is the PHP Manual link: http://php.net/manual/en/function.curl-errno.php
and description of error: http://web.mit.edu/jhawk/mnt/ss.b/curl-7.10.5/docs/libcurl/libcurl-errors.html
You can use curl_error to capture the error How to catch curl errors in PHP
Other thing to consider here is your proxy, is it allowed to access the host and port you are trying to access and you access the host without proxy?
CURLE_FTP_WEIRD_SERVER_REPLY (8)
The server sent data libcurl couldn't parse. This error code is used for more than just FTP and is aliased as CURLE_WEIRD_SERVER_REPLY since 7.51.0.
CURLE_REMOTE_ACCESS_DENIED (9)
We were denied access to the resource given in the URL. For FTP, this occurs while trying to change to the remote directory.
CURLE_FTP_ACCEPT_FAILED (10)
While waiting for the server to connect back when an active FTP session is used, an error code was sent over the control connection or similar.
CURLE_FTP_WEIRD_PASS_REPLY (11)
After having sent the FTP password to the server, libcurl expects a proper reply. This error code indicates that an unexpected code was returned.
CURLE_FTP_ACCEPT_TIMEOUT (12)
During an active FTP session while waiting for the server to connect, the CURLOPT_ACCEPTTIMEOUT_MS (or the internal default) timeout expired.
for more details
enter link description here
CURLE_FTP_ACCEPT_TIMEOUT (12)
During an active FTP session while waiting for the server to connect, the CURLOPT_ACCEPTTIMEOUT_MS (or the internal default) timeout expired.
Related
I have two servers, one is my webserver, for my website, and the other one is my discord bot hosting server. My setup is when a certain action occurs on the webpage, it'll use cURL to post to the node.js server (the discord bot), which would then return some data.When it was in development and I was creating it on my localhost, it worked perfect (both servers were locally hosted). When I take the servers and run them on their respective services, I am given a connection refused error from cURL, same with file_get_contents().
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'http://51.161.93.27:8109/');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$data = curl_exec($ch);
echo "<pre>";
var_dump( curl_getinfo($ch) ) . '<br/>';
echo curl_errno($ch) . '<br/>';
echo curl_error($ch) . '<br/>';
curl_close($ch);
If I run this exact code from localhost instead of the webserver, it works and gets the data. On the webserver I can not post or get.
On the webserver, if I remove the port from the CURLOPT_URL, it'll connect to the main ip and return stuff. Same if I put www.google.com. This means cURL works, just can't connect to the port itself.
Note, the specific port is being run with the node.js http module along with express.
The webserver is being run from namecheap, and using cpanel. The discord bot hosting service is called pebblehosting.
Feel free to use the address, http://51.161.93.27:8109/ to find some more information, its the bot address. If able to succesfully get data from it, it should display a json string with a message stating {"status":"fail. You already have a ticket open"}.
I also connected to the address from services like ping.com and was able to connect.
I have spent all day trying to find a solution, but couldn't find anything.
I have been using cURL code to access Beanstream for awhile now, and all of a sudden it stopped working as of yesterday. I have determined that this has to do with accessing the HTTPS URL for Beanstream processing, as if I test that same code and just go to the HTTP URL, it works (of course it returns an insecure connection code).
Prior to the below code I was setting VERIFYPEER / VERIFYHOST to FALSE, which was working up until yesterday.
$url = 'https://www.google.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, "/xxxx/public_html/_cert/GeoTrustGlobalCA_google.crt");
$getResponse = (curl_exec($ch));
curl_close($ch);
print_r($getResponse);
I have setup the above test code to try and access Google via HTTPS. I had read that a proper connection requires the VERIFYPEER / CAINFO options to be set, which I have done and grabbed the Google .crt and placed it on the web server as well.
I still get a 503 Service Unavailable error back though.
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Additionally, a 503 Service Unavailable error was encountered while
trying to use an ErrorDocument to handle the request.
The below php code is making a REST API call that returns json object. This works fine when i use it on my localhost using WAMP Absolutely no problem.
However when i push this app on the server it would TimeOut and display 503 Service Unavailable.
I checked the logs it has an entry :
The TimeOut Specified has expired.
I contacted my admin he just said this app listens to PORT=64665 and HOST=0.0.0.0. What does that mean? What more changes do i need to make in my code to make it work on the server ? Help
<?php
$url = "http://xyz.net/v2/plan/"; // I have changed the REST URI API Link for security reasons
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, false);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
// Will dump json
var_dump(json_decode($result, true));
$response = "http://xyz.net/v2/plan/";
echo $response;
?>
Check your server's /etc/hosts file, there could be the problem, ie. domain mapped to another (wrong) IP address.
basically, this error only occurs in CURL
curl: (56) Recv failure: Connection reset by peer
But when I visit it directly the link directly on my browser, it works!
What are your recommendations on fixing this one or the cause of this error?
Note: the server is coded in ASP and it only occurs on one API Call
I resolved this issue by removing whitespace characters from the URL. In my situation, it was the proxy server that was erroring out, not the web server.
In PHP:
curl_setopt($ch, CURLOPT_URL, trim($url));
I remember facing the same issue a long time back. While I don't remember what exactly sorted out the issue, I remember trying the following:
I was trying to pass the query parameters in the URL directly and I tried passing through POST method
I tried using a proxy with curl to see if I was possibly being blocked by the other server
I believe I also asked my host to look into it and they made some Apache setting changes
I had similar problem with this code:
$url = "http://xxx.xxx.xxx.xxx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_PORT, 44455); //Set the port to connect to
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 44455);
curl_setopt($ch, CURLOPT_URL, $url);
echo $xml = curl_exec($ch);
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
Got it solved by disabling this:
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 44455);
I have a script with line:
$id = strtolower(implode('',file($ip_service . $ip)));
When executed the file function will be like file(http://www.url.com/filename.php?119.160.120.38)
On server A it works fine but on Server B it gives following error:
file(http://www.url.com/filename.php?xxx.xxx.xxx.xxx) [function.file]: failed to open stream: Connection timed out in /home/path/filename.php on line 22
Line 22 is the above line of code.
Server A has PHP 4.4.6, Server B has 4.4.8
Any help will be highly appreciated.
Using file() and/or file_get_contents() for accessing files across the internet is fairly error prone. For example, I don't think they follow redirects. The timeout period is also very short, not the typical network timeout. It's also difficult to do error capture to see why it failed.
I always use CURL for accessing files over the network. It takes a few more lines of code, but is much more reliable. Note, PHP CURL support may not be installed in your setup.
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_URL, 'http://www.url.com/filename.php?119.160.120.38');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
if ( $result==false ) {
echo curl_errno($ch).' '.curl_error($ch);
}
curl_close($ch);
Obviously you would want to do something beside echo out the error message if there was an error. The $result variable will have the contents of the file if it succeeds.
Your server couldn't establish a tcp/ip connection to the server hosting www.url.com in a given time period (20 seconds? 30 seconds? What ever the default is or what you have specified as timeout). The other server didn't even reject the connection actively, there just wasn't any response at all. Could be e.g. a firewall issue where some or all of your or the other server's packets where silently dropped.