Saturday, March 7, 2009

URL read in PHP

file_get_contents with proxy server:
<?php
$context = array (
'http' => array (
'proxy' => 'hostIP:hostPort', 'request_fulluri' => true,
),
);
$context = stream_context_create ($context);
$data = file_get_contents("http://www.fevoxtech.com",0,$context);
echo $data;
?>

file_get_contents without proxy server:

<?php
$data = file_get_contents("http://www.fevoxtech.com",0);
echo $data;
?>

cURL with proxy server:

<?php
$url = "http://www.fevoxtech.com";
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_PROXY, IP Address);
curl_setopt($ch, CURLOPT_PROXYPORT, Port No);
$file_contents = curl_exec($ch);
curl_close($ch);
?>

cURL without proxy server:

<?php
$url = "http://www.fevoxtech.com";
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
?>

No comments:

Post a Comment