开发者

Which PHP function best suited for retrieving web server data

I thought an interesting way of recording my browsing or performing certain tasks upon viewing particular websites, would be to create some sort of overlay (front end) to sit at the top of my browser view window and have PHP in the back parse web server data. These are very common for services such as script based proxies and advertising.

If I were to use PHP to save plain text copies of wikipedia articles as I view t开发者_JS百科hem, an offline cache if you will, which method of retrieving the data would be the most appropriate?

Using stream functions (file_get_contents, file etc..) or cURL/core PHP HTTP requests or even sockets? (although tinkering with TCP/IP wouldn't be the simplest method).


Use file_get_contents() if you're only retrieving data, it's the easiest method and is always available.

If you'll need to POST data, use cURL (a php-extension so it isn't guaranteed to be enabled on your server)

Sockets are only needed if you'll need something other than http, https or ftp.
(For supported protocols check "Registered PHP Streams" in your phpinfo)

If you want to download a page including css, etc you might want to look into wget
A standard linux commandline tool to download content.

<?php
chdir('/path/to/store/the/files/');
system('wget -E -H -k -K -p -nd http://www.example.com/'); // use passthru() instead of system if you want to see the output/errors.
?>

(I don't know what all those parameters mean, i just copied this snippet from here, checkout the manual for details)


I'm pretty sure that cURL would be your best alternative. Easy to get started with, easy to adjust to your needs and very powerful. Learn more: http://php.net/manual/en/book.curl.php


I saw once the a component of the Zend Framework as an http client.
I think it's the most easy and powerful to do such spider. I am trying to remeber what was its name.

It's Zend_Http_Client. Example:

$client = new Zend_Http_Client('http://wiki/');
$response = $client->request(); 
print_r($response->getBody());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜