Sorry 4 long post (necessary)
-----------------------------

Hi.
I decided to post this msg coz i'm almost tired of "fighting" with 
php...
I begun some time ago looking in php anything that would allow me to 
make a
connection to another host. Then i discovered in the PHP's manual ( 
Spanish CHM edition )
some stuff about sockets.
Then when i begun reading i found:

"The socket extension implements a low-level interface to the socket 
communication functions, providing the possibility to act as a socket 
server as well as a client."

Then i realized that my php needed a sockets extension.
Then i downloaded latest php and found in php.ini the following line
;extension=php_sockets.dll
Then, i deleted the ; and activated that line.

The thing is that when i copied the example found in the manual and run 
i got an error !!
I supposed that SOCKET function sould be in php_sockets.dll but it seems 
i'm wrong BECAUSE when
i run the example i got
"Fatal error: Call to undefined function: socket() in c:\inetpub\clcswi
\test.php on line 13"
WELL, WHERE IS THIS FUNCTION !?

So, i'd like to know what can i do to enable this function in my php, 
then
How can i connect to a tcp server (using or not this NON-EXISTING 
function) and send a string...?

Thanks

test.php (the example located in chm manual)

<?php
error_reporting(E_ALL);
echo "<h2>TCP/IP Connection</h2>\n";
/* Get the port for the WWW service. */
$service_port = getservbyname('www', 'tcp');
/* Get the IP address for the target host. */
$address = gethostbyname('www.php.net');
/* Create a TCP/IP socket. */
$socket = socket(AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
    echo "socket() failed: reason: " . strerror($socket) . "\n";
} else {
    "socket() successful: " . strerror($socket) . "\n";
}
echo "Attempting to connect to '$address' on port '$service_port'...";
$result = connect($socket, $address, $service_port);
if ($result < 0) {
    echo "connect() failed.\nReason: ($result) " . strerror($result) . 
"\n";
} else {
    echo "OK.\n";
}
$in = "HEAD / HTTP/1.0\r\n\r\n";
$out = '';
echo "Sending HTTP HEAD request...";
write($socket, $in, strlen($in));
echo "OK.\n";
echo "Reading response:\n\n";
while (read($socket, $out, 2048)) {
    echo $out;
}
echo "Closing socket...";
close($socket);
echo "OK.\n\n";
?>

----------------------------------
Henry - Argentina
http://www.quiquesistemas.com.ar
[EMAIL PROTECTED]
ICQ: 18048153

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to