开发者

PHP fsockopen()

a simple short question can i pass the host's ip in the fsockopen() function instead of its name?i need to set a connection between 2 servers and right now i have to work on the same computerm,I've never used fsockopen before so a simple example is appreciated Thanks in advan开发者_C百科ce =)


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜