PHP fsockopen()
I'd say, instead of using fsockopen()
to do HTTP between the two servers, it would be easier to use curl
then, because it already has anything you would need.
Technically, if you use fsockopen()
to do HTTP communication, you are going to develop another HTTP client. As curl is an HTTP client, I can't see the need to reinvent the wheel^^
EDIT:
So you really must use fsockopen()
?
Ok. Here's a link to Simon Willisons PHP HTTP client. Maybe it's old and outdated, and covers only a very small subset of an HTTP client functionality, but it comes with source and should help you getting on track on how to use fsockopen
to do an HTTP request.
for e.g.
fsockopen(gethostbyaddr("127.0.0.1"), ...
using fsockopen function does't secure. This function often disabled by hosting providers for security reasons, also hosting providers have protect from foreign connections to other machines by firewall.
If you want to get something by one server from another using php, just use CURL. You need installed curl php extension to use it.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://yourserver.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
$r = curl_exec($ch);
curl_close($ch);
?>
Also if you use Zend Framework, you can set eyes on Zend_Http_Adapter_Curl classes
精彩评论