note 57872 added to ref.curl

From: Date: Mon, 17 Oct 2005 14:43:38 +0000
Subject: note 57872 added to ref.curl
Groups: php.notes 
Request: Send a blank email to php-notes+get-97120@lists.php.net to get a copy of this message
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); ?> ---- Manual Page -- http://www.php.net/manual/en/ref.curl.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57872 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57872&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57872&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57872&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57872&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57872&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57872&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57872&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57872&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97120) next »