RE: [PHP] Some questions regarding pfsocketopen()
| From: | Michael J. Pawlowsky | Date: | Thu, 02 Jan 2003 20:36:27 +0000 |
| Subject: | RE: [PHP] Some questions regarding pfsocketopen() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-129984@lists.php.net to get a copy of this message | ||
You will need to have everythng on the same page. Your program ends once the page does.
Here are some examples straight from the manual.
<?php
$fp = fsockopen ("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET / HTTP/1.0\r\nHost: www.example.com\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
?>
The example below shows how to retrieve the day and time from the UDP service "daytime"
(port 13) in your own machine. Example 2. Using UDP connection
<?php
$fp = fsockopen("udp://127.0.0.1", 13, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br>\n";
} else {
fwrite($fp,"\n");
echo fread($fp, 26);
fclose($fp);
}
?>
*********** REPLY SEPARATOR ***********
On 02/01/2003 at 3:10 PM Gareth Hastings wrote:
>One last question, do you know how or what method I would use to do this
>via a php script? Everything I've tried fails. Like
>
>
>Makeconnection.php
><?
> $mysocket = pfsocketopen('my.server.com', '1234');
>?>
>--------------
>
>
>testconenction.php
><?
> fputs($mysocket, "VERSION\n");
> echo fgets($mysocket, 255);
>?>
>