I have two computers. I have configured web server on both computers and both are working. Now I want to access 1st URL from 2nd 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 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 As I can access other files using file_get_contents() but not this one which I want. So please help me to solve this problem.
I have checked all PHP configuration on both servers but if anybody wants to check, use the following URLs:
http://46.7.234.111:8080/phpinfo.phphttp://spicegururathgar.ie/phpinfo.php
Please ignore the file names ;)
I’m facing this problem only when I’m trying to run code from spicegururathgar.ie server, does any one know why this is happening?
Alternate try
I have also tried using PHP CURL but still I’m getting the same error. Here is my PHP CURL code. This code is working on my localhost but not on my server. Please help me with this.
$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;
telnet 46.7.234.111 8080from the shell on the first machine?