firebaseio.com refusing connections after many requests - php

I use PHP CURL for making changes to the Firebase database. After many curl requests, suddenly, Failed to connect to something.firebaseio.com port 443: Connection refused error occours. After few hours, it starts working again.
Following is the curl script in php
$url = 'https://something.firebaseio.com/iochatting/roomchats/data.json?auth=private_key';
$json = json_encode($msg);
$headers = array();
$headers[] = 'Content-Type: application/json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 20500);
$response = curl_exec($ch);
if ($response === FALSE) {
}
curl_close($ch);
This code works fine most of the time but suddenly all connection requests are rejected.
Also, i have tried https://github.com/kreait/firebase-php , this too stops suddenly.
I want the curl to work not the php-sdk. Is there anyway ? Is google refusing server request ?
When the connections are rejected when sending request normally, if i use proxy in of port 443. It works again for few times.

Related

cURL php request with ip and port

I would like to develop a script which, at the submit of a form, send a request to an url using ip adress and port in order to send an sms via the gateway configured on my phone.
The url I have
$url = "192.168.1.31:43382/send.html?smsto=XXXXXXXXXX&smsbody=test&smstype=sms";
And my cURL code :
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$verbose = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $verbose);
$result = curl_exec($ch);
curl_close($ch);
It works fine localy until I put it on my server.
When I log verbose's value, I get this :
Hostname was NOT found in DNS cache
Trying 192.168.1.31...
connect to 192.168.1.31 port 43382 failed: Connection timed out
Failed to connect to 192.168.1.31 port 43382: Connection timed out
Closing connection 0
I've seen that it could be a firewall issue, so I disabled it but nothing new.
I'm new to cURL, if someone could guide me...
Thanks

Failed to connect to : Connection refused - cURL PHP

So here's the scenario.
1) On my local machine that is running MAMP, I'm not facing any issue and I'm able to successfully get the response along with CURLINFO_HTTP_CODE=200
2) However, there is a remote server on which my PHP code is deployed. If I try to run the same thing (as I've mentioned in #1) I get an error that says
curl_error = Failed to connect to my_ip port my_port: Connection refused with CURLINFO_HTTP_CODE = 7
$url = 'myURL';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,30); //timeout in seconds
curl_setopt($ch,CURLOPT_TIMEOUT, 20); // same for here. Timeout in seconds.
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$data_string = {"name":"mark"} `
In my case, call API from localhost was successful, but when i call API from online website i get error(connection refused). that's because the IP of API was available on our internal network(company network), not on the internet. i know it's silly mistake.

laravel curl not working on azure

I am connecting my two apps (laravel with python) using curl command. It is working absolutely fine on my local server without changing a single line but when it gives me following error when on azure server
POST https://myweb.com/searchJobs 500 ()
my code is
$ch = curl_init();
//URL to send the request to
curl_setopt($ch, CURLOPT_URL, 'http://python-scrapper-python001.azurewebsites.net/myfunction');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
//We are doing a post request
curl_setopt($ch, CURLOPT_POST, 1);
//adding the post data to request
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
//Return instead of outputting directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
is there any security protocol that I need to update on azure or what can be possible issue?
Actually these lines were working fine on localhost but not on azure
$arr = "";
$arr['hello'] = '7';
so I changed them as
$arr = [];
$arr['hello'] = '7';
Though i don't no why azure didn't run it. If php convert it to an array on localhost than it must run on azure as well
Since you are using the default domain provided by azure appservice. Instead of just using the HTTP protocol try to use the HTTPS since this is already free on the default domain provided. in this case try this changes.
$ch = curl_init();
//URL to send the request to
curl_setopt($ch, CURLOPT_URL, 'https://python-scrapper-python001.azurewebsites.net/myfunction');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
//We are doing a post request
curl_setopt($ch, CURLOPT_POST, 1);
//adding the post data to request
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
//Return instead of outputting directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);

PHP CURL Never Ending Request

I recently uploaded my project from localhost to a live hosting server. In my project I have used a CURL request, which worked absolutely fine on localhost up til now.
As soon as I moved it on live server (Arizonawebservices.com), that CURL request stopped working. When my page sends the CURL request, it keeps on processing and never returns any output.
I checked server for CURL support (using "which curl" command in PHP's exec() function), and yes it has CURL support enabled.
Also created a test page for manually shooting CURL requests and check if it works ok. Tried www.google.com, www.yahoo.com, and many other URLs, all are working fine, but when I put my original API URL "https://dataviz.sandbox.rcoanalytics.com:10105/oauth/token" in it. It starts behaving like before. I am completely unable to get any response from that CURL request. Any help would be appreciated.
Used following code for testing purpose:
function httpPost($url,$params)
{
$postData = '';
if (!empty($params)) {
//create name value pairs seperated by &
foreach($params as $k => $v)
{
$postData .= $k . '='.$v.'&';
}
$postData = rtrim($postData, '&');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
if ($postData != "") {
curl_setopt($ch, CURLOPT_POST, count($postData));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
}
$output=curl_exec($ch);
if($output === false)
{
echo "Error Number:".curl_errno($ch)."<br>";
echo "Error String:".curl_error($ch);
}
curl_close($ch);
return $output;
}
$params = array(
);
echo httpPost("https://dataviz.sandbox.rcoanalytics.com:10105/oauth/token", $params);
The url has an SSL error, so in the cURL request when cURL tries to verify the host it blocks you from accessing the address.
use the following:
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
This is obviously insecure method to access the URL but for a host like this one it will do the trick.

TTY and/or ARF Response from Experian's API

I'm trying to use the PHP Curl library to connect to Experian's API.
When I post a HTTPS request to Experian, I get an HTTP 200 OK response, but nothing more. I am expecting a TTY or ARF response. Do anyone have insight in what I'm doing wrong?
Here's a snippet of my code below for reference
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'http://stg1.experian.com/lookupServlet1?lookupServiceName=AccessPoint&lookupServiceVersion=1.0&serviceName=NetConnectDemo&serviceVersion=2.0&responseType=text/plain'); //not the actual site
//For Debugging
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST,1);
//#2-Net Connect client receives ECALS response. This is the Net Connect URL.
$ecals_url = curl_exec($ch);
//#3-Net Connect client validates that the URL ends with “.experian.com”. If the URL is valid, the processing continues; otherwise, processing ends.
$host_name = parse_url( $ecals_url );
$host_name = explode(".", $host_name['host'] );
$host_name = $host_name[1].'.'.$host_name[2];
if( $host_name == "experian.com" )
{
//#4-Net Connect client connects to Experian using URL returned from ECALS.
echo "step 4 - connect to secure connection<br>";
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch,CURLOPT_URL,$ecals_url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");
curl_setopt($ch,CURLOPT_CERTINFO,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10s
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec ($ch);
print_r ($result);
It has been a while since I messed with our Experian Net Connect service but I believe you have to base64 encode the username:password value for their system to take it.

Categories