Problem using file_get_contents ()

I have two computers. I set up a web server on both computers and both of them work. Now I want to get the 1st URL from the second using file_get_contents().

1st URL:

http://46.7.234.111:8080/server/test_curl.php

2nd URL:

http://spicegururathgar.ie/client/test_curl.php

Code for accessing the 1st URL:

$url = "http://46.7.234.111:8080/server/test_curl.php";
$url = 'http://' . str_replace('http://', '', $url); // Avoid accessing the file system
$opts = array('http' => array('header' => "User-Agent:MyAgent/1.0\r\n"));
$context = stream_context_create($opts);
$header = file_get_contents('$url', false, $context); // Not working
//$header = file_get_contents('http://wordpress.org/plugins/about/readme.txt', false, $context); // Working Fine

Apache Error Log:

[27-Dec-2013 08:31:12 UTC] PHP Warning:  file_get_contents(http://46.7.234.111:8080/server/test_curl.php) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: Connection timed out in /home/spicegur/public_html/client/test_curl.php on line 6

How can I access other files using file_get_contents(), but not the one I want. So please help me solve this problem.

I checked the entire PHP configuration on both servers, but if someone wants to check, use the following URLs:

  • http://46.7.234.111:8080/phpinfo.php
  • http://spicegururathgar.ie/phpinfo.php

Please ignore the file names;)

Im only encounters this problem when Im trying to run code from the server spicegururathgar.ie, does anyone know why this is happening?

Alternative try

PHP CURL, Im . PHP CURL. localhost, . , .

$runfile = "http://46.7.234.111:8080/server/test_curl.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $runfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL,$runfile);
$content = curl_exec($ch);
curl_close($ch); 
echo $content;
+4
8

$header = file_get_contents('$url',false,$context);//Not working

$header = file_get_contents($url,false,$context);//Not working

. , . , , , .

+9

PHP- , $url, Apache URL-, , .

, spicegururathgar.ie , test_curl.php, -. , , test_curl.php , , spicegururathgar.ie.

, , - :

$opts = array('http' => array(
  'header' => "User-Agent:MyAgent/1.0\r\n",
  'timeout' => 60*5 // 5 minutes
));
+4

$url 6 :

$header = file_get_contents("$url", false, $context);

$header = file_get_contents($url, false, $context);
+2

cUrl, _get_contents, - cUrl. , .

function curl_get_contents($url)
{   
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}
+2

wget http://46.7.234.111:8080/phpinfo.php spicegururathgar.ie . , 8080 , 80, 433 ..

80.

.

+1

Fiddler, , - . -, ( ).

+1

, . , (46.7.234.111:8080/server/test_curl.php) . (spicegururathgar.ie/client/test_curl.php).

+1

. allow_url_fopen :

http://php.net/manual/en/filesystem.configuration.php

This is to protect the server. In your case, there is no security problem, so it can be resolved.

-1
source

All Articles