note 57872 deleted from ref.curl by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 19:36:15 +0000 |
| Subject: | note 57872 deleted from ref.curl by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155240@lists.php.net to get a copy of this message | ||
Note Submitter: admin at sellchain dot com
----
TIP: If you are using fopen and fread to read HTTP or FTP or Remote Files, and experiencing some
performance issues such as stalling, slowing down and otherwise, then it's time you learned a
thing called cURL.
Performance Comparison:
10 per minute for fopen/fread for 100 HTTP files
2000 per minute for cURL for 2000 HTTP files
cURL should be used for opening HTTP and FTP files, it is EXTREMELY reliable, even when it comes to
performance.
I noticed when using too many scripts at the same time to download the data from the site I was
harvesting from, fopen and fread would go into deadlock. When using cURL i can open 50 windows,
running 10 URL's from each window, and getting the best performance possible.
Just a Tip :)
Also here is some quick code that I use in my scripts now, of course credits go to other
PHP'ers who have posted on this page, so I take zero credit.
TO POST TO A PAGE USING values and fields:
<?
$url="http://anything";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS,
"fieldname=fieldvalue&fieldname=fieldvalue&");
#curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$content = curl_exec ($ch); # This returns HTML
curl_close ($ch);
?>
TO GET A PAGE USING A URL ONLY:
<?
$url="http://anything";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$xml = curl_exec ($ch);
curl_close ($ch);
?>