RE: [PHP] resource handle - keeping alive?

From: Date: Mon, 10 Nov 2003 17:03:13 +0000
Subject: RE: [PHP] resource handle - keeping alive?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-169055@lists.php.net to get a copy of this message
Hi, > sounds like a good idea. How does 'gateway' actually listen in on the > website session? > > Is it simply invoked by the website with specific arguments? It has a socket connection that waits for an incoming request from the web site, and then it takes what was sent from the web site, processes it, and sends a response. here's some code: Perl: #!/usr/bin/perl use IO::Socket; $SIG{CHLD} = sub { wait () }; my $nc_sock = new IO::Socket::INET ( LocalHost => '192.168.3.4', LocalPort => '7070', Proto => 'tcp', Listen => 5, Reuse => 1 ); while ( $nclive_sock = $nc_sock->accept() ) { $pid = fork(); if ($pid == 0) { while ( defined( $buf = <$nclive_sock> ) ) { print $buf; if ( substr( $buf, 0, 3 ) eq '000' ) { print $nclive_sock "4230999999000000004111111111111111470002220001999977777777777777777777423\n "; } else { print $nclive_sock "Hello to you too!\n"; } } exit(0); } } close ( $nc_sock ); Here is the PHP Web site: $fp = fsockopen ("192.168.3.4", 7070, $errno, $errstr, 90); if ( !$fp ) { echo "$errstr ($errno)<br>\n"; } else { fputs ( $fp, "$auth_msg\n" ); $response = process_response( fgets( $fp ) ); printf( "%s - %s", process_code( $response['code'] ), $response['msg'] ); fclose( $fp ); } Hope that helps... -Dan Joseph

« previous php.general (#169055) next »