I am a PHP newbie (just got my "Hello World" page working this
morning). I'm doing some R&D work to see if PHP is viable for a
situation I have. To accomplish what I want to do, I have to have the
PHP page communicate directly with another process.
I want the PHP script to establish a socket connection to the other
process, send a message and receive some data back which would then
used for calculations and/or display on the resulting page. The PHP
page will be the client - the other process will be the server. The
server process is a program that I've written using Visual Basic 6 and
the socket there is the standard Winsock that's part of VB.
Shown below is the entire page that I'm using to test this concept;
I've adapted it from an example provided in the "Socket Functions"
section of the manual on the PHP.net website. Amazingly enough, this
actually works - up to a point. I'm hoping someone here can help get
it working all the way through.
This script works up to the point of reading the response. It creates
the connection (my server process accepts the connection and receives
the "Hello world" message). The server sends its message. But then the
script seems to just sit there - it doesn't complete - it doesn't
generate any output.
Can anyone suggest what I might need to do to get this to work?
If it matters, I'm using PHP 5.0.1, IIS 5.1 running on Windows XP with
service pack 2.
Thanks
-----------------------------------------------------------------------------------
<HTML>
<BODY>
<?php
echo "<h2>TCP/IP Connection</h2>\n";
$service_port = 1001;
$address = "192.168.200.19 ";
$socket = socket_create(A F_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
echo "socket_create( ) failed: reason: " . socket_strerror ($socket)
.. "<br>";
} else {
echo "OK.<br>";
}
echo "Attempting to connect to '$address' on port '$service_port' ...";
$result = socket_connect( $socket, $address, $service_port);
if ($result < 0) {
echo "socket_connect () failed.\nReason : ($result) " .
socket_strerror ($result) . "<br>";
} else {
echo "OK.<br>";
}
$in = "Hello World";
$out = "";
echo "Sending message...";
socket_write($s ocket, $in, strlen($in));
echo "OK.<br>";
echo "Reading response: <br><br>";
while ($out = socket_read($so cket, 999, PHP_NORMAL_READ )) {
echo $out;
}
echo "<br>Closin g socket...";
socket_close($s ocket);
echo "OK.<br><br >";
?>
</BODY>
<HTML>
morning). I'm doing some R&D work to see if PHP is viable for a
situation I have. To accomplish what I want to do, I have to have the
PHP page communicate directly with another process.
I want the PHP script to establish a socket connection to the other
process, send a message and receive some data back which would then
used for calculations and/or display on the resulting page. The PHP
page will be the client - the other process will be the server. The
server process is a program that I've written using Visual Basic 6 and
the socket there is the standard Winsock that's part of VB.
Shown below is the entire page that I'm using to test this concept;
I've adapted it from an example provided in the "Socket Functions"
section of the manual on the PHP.net website. Amazingly enough, this
actually works - up to a point. I'm hoping someone here can help get
it working all the way through.
This script works up to the point of reading the response. It creates
the connection (my server process accepts the connection and receives
the "Hello world" message). The server sends its message. But then the
script seems to just sit there - it doesn't complete - it doesn't
generate any output.
Can anyone suggest what I might need to do to get this to work?
If it matters, I'm using PHP 5.0.1, IIS 5.1 running on Windows XP with
service pack 2.
Thanks
-----------------------------------------------------------------------------------
<HTML>
<BODY>
<?php
echo "<h2>TCP/IP Connection</h2>\n";
$service_port = 1001;
$address = "192.168.200.19 ";
$socket = socket_create(A F_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
echo "socket_create( ) failed: reason: " . socket_strerror ($socket)
.. "<br>";
} else {
echo "OK.<br>";
}
echo "Attempting to connect to '$address' on port '$service_port' ...";
$result = socket_connect( $socket, $address, $service_port);
if ($result < 0) {
echo "socket_connect () failed.\nReason : ($result) " .
socket_strerror ($result) . "<br>";
} else {
echo "OK.<br>";
}
$in = "Hello World";
$out = "";
echo "Sending message...";
socket_write($s ocket, $in, strlen($in));
echo "OK.<br>";
echo "Reading response: <br><br>";
while ($out = socket_read($so cket, 999, PHP_NORMAL_READ )) {
echo $out;
}
echo "<br>Closin g socket...";
socket_close($s ocket);
echo "OK.<br><br >";
?>
</BODY>
<HTML>
Comment