I have a script. It's using file_get_contents. I heard that curl is more efficient from file_get_contents what is the equivalent code for curl? $data = file_get_contents("http://www.xxx.com"); I want this with curl . How can i do it ?
<?php $url = 'http://www.xxx.com'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); $data = curl_exec($ch); ?> PHP: The good thing about cURL is that you can set all possible options manually, incase the server you're requesting this from requires it. http://us2.php.net/curl
Be careful if you plan to make a public script. cURL isn't enabled by default and not all hosts support it. Do something like this: if (function_exists('curl_init')) { // Use cURL } else { // Use file_get_contents } PHP:
thank you for more information . Now I tested it's working %100 . My script was making 100 job in 60 seconds . now it make it in 14 seconds. I advise it to everyone