Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to make php curl request with port number

Tags:

php

curl

port

I am unable to make a php curl request with port number , without port number i am getting response properly.

Through terminal when i do curl http://www.sample.com:8088 i am getting response back properly. But not through php curl on doing curl_inf() i am getting

Array ( [url] => http://www.sample.com:8088/ [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => 0 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ( ) ) 

My code

$url = "http://www.sample.com:8088/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, True);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
$report=curl_getinfo($ch);
print_r($report);
$result = curl_exec($ch);
curl_close($ch);
echo $result;

this code give me response from ubuntu , but not giving response from cent os if port number is specified.

Please let me know the how to fix it.

THanks in advance.

like image 534
druveen Avatar asked Aug 25 '11 10:08

druveen


People also ask

Can you cURL TCP?

Connections - Everything curl. Most of the protocols you use with curl speak TCP. With TCP, a client such as curl must first figure out the IP address(es) of the host you want to communicate with, then connect to it. "Connecting to it" means performing a TCP protocol handshake.

How does PHP handle cURL request?

PHP cURL download file php $ch = curl_init('http://webcode.me'); $fp = fopen('index. html', 'w'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, false); curl_exec($ch); if (curl_error($ch)) { fwrite($fp, curl_error($ch)); } curl_close($ch); fclose($fp);

How cURL URL in PHP?

php file with the following contents. $url = 'https://www.example.com' ; $curl = curl_init(); curl_setopt( $curl , CURLOPT_URL, $url );


2 Answers

Try to set the port like this:

curl_setopt($ch, CURLOPT_PORT, $_SERVER['SERVER_PORT']);

or:

curl_setopt($ch, CURLOPT_PORT, 8088);
like image 110
Mário Rodrigues Avatar answered Sep 20 '22 08:09

Mário Rodrigues


Try to set

curl_setopt($ch,CURLOPT_PORT, 8088);

See more info http://php.net/manual/en/function.curl-setopt.php

like image 24
Andrej Ludinovskov Avatar answered Sep 22 '22 08:09

Andrej Ludinovskov