简体   繁体   中英

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 advance =)

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 eg

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM