jd2007 Posted July 13, 2007 Share Posted July 13, 2007 what php built-in functions are usually used for web fetching ? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 13, 2007 Share Posted July 13, 2007 fetching? as in getting data off a url? try fopen or cURL or socket type connection if you are trying to get info off an outside server fopen(opens a doc post processing and you get the doc's entire length (tricky,copy right infractions, but can be useful at times) cURL(sends info off to a processor type page and returns with info back. (good for like stock look ups) socket(makes a connection to a server and can extract data from flat files (paypal uses this for IPN in which data is stored in flat files for cross language use Quote Link to comment Share on other sites More sharing options...
rtpmatt Posted July 13, 2007 Share Posted July 13, 2007 I think you might be looking for snoopy: http://sourceforge.net/projects/snoopy/ hope that helps. -matt Quote Link to comment Share on other sites More sharing options...
Glyde Posted July 13, 2007 Share Posted July 13, 2007 There really is no need for anything like snoopy. You can create your own sockets or curl connections fairly simply. Try something like: <?php function getPageData($pageurl) { $_url = parse_url($pageurl); $port = strtolower($_url['scheme']) == 'https' ? 443 : 80; $_sck = fsockopen($_url['host'], $port, $errNo, $errStr); if (!$_sck) { die("Socket error [#$errNo]: $errStr"); } $path = $_url['path'] . '?' . $_url['query']; $request = "GET $path HTTP/1.1\r\n"; $request .= ($port == 443) ? "Host: {$_url['host']}\r\n"; $request .= "Connection: close\r\n\r\n"; fputs($_sck, $request, strlen($request)); $response = ''; while (!feof($_sck)) { $response .= fgets($_sck, 1024); } echo $response; } getPageData('http://google.com/index.html'); ?> Tested, works, and a hell of a lot smaller than snoopy. Granted it doesn't have the features, but if all you need is to pull data from a website...there you go. Actually, there's also a much much easier way: <?php print implode("\n", file("http://google.com/index.html")); ?> But that won't always work. You shouldn't have a problem with sockets. Quote Link to comment Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 You can even use file_get_contents for simple GET requests! <?php print file_get_contents("http://www.google.com"); ?> Quote Link to comment Share on other sites More sharing options...
Glyde Posted July 13, 2007 Share Posted July 13, 2007 You can even use file_get_contents for simple GET requests! <?php print file_get_contents("http://www.google.com"); ?> Yes, but it's PHP5 only, which is why I did the file() example in mine...backwards compatibility. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.