That's the first thing I tried- doesn't work with the lower-level sockets. 
(the socket_* functions)

Right now I have an fsockopen version, and I'm commenting out the socket 
version- hopefully I'll be able to get it to work later.

Thanks, but do you have any other ideas???


-Evan






On Monday 04 February 2002 14:53, you wrote:
> I've found fsockopen to be very reliable.  I've done a few socket scripts
> with PHP (WhoisPro, et al).
>
> I believe the easiest way to check for a remotely closed socket is to do an
> fgets() and check for EOF:
>
>    while (!feof($connection)) {
>     $buffer .= fgets($connection, 4096);  // 4096 is the chunk size, you
> can adjust it
>    }
>
> I *think* EOF on a socket deonotes a remote socket close but I could be
> horribly wrong.
>
> Mike Frazer
>
>
>
> "Evan Nemerson" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> > I am aware of cURL, but I want to just use the standard PHP stuff if I
> > can because I plan on releasing this when I'm done, and want to KISS for
> > other people.
> >
> > I know people have to compile PHP with sockets, but they will anyways for
> > this project- I'm going to need socket_listen and socket_create_listen
>
> too.
>
> > This is for a proxy server which will work kinda like multiproxy, but
>
> should
>
> > be more powerful. It will support direct connections or going through
>
> another
>
> > proxy server. It seperates anonymous from non-anonymous proxy servers,
>
> then
>
> > sorts them by speed. Data is stored in tab seperated value text files
> > (I'm even avoiding mySQL!!!)
> >
> > I just signed up for a page @ sourceforge. If anyone is interesting in
> > helping out e-mail me.
> >
> > Thanks for the idea, though. I think right now my fall-back is fsockopen.
>
> I
>
> > would really love to get sockets working for this...
> >
> > On Sunday 03 February 2002 23:32, you wrote:
> > > A quick note...
> > >
> > > If you are not aware of cURL (curl.haxx.se), then you may want to look
>
> into
>
> > > it.
> > >
> > > If you are, then please disregard this post.
> > >
> > > -Jason Garber
> > >
> > > At 11:06 PM 2/3/2002 -0800, Evan Nemerson wrote:
> > > >Anyone know if there is a way yet to see if a socket is still
> > > > connected
>
> to
>
> > > > a host? I want to use a socket to send "GET / HTTP/1.0\r\n\r\n" over
> > > > a socket, and retrieve everything the server sends. That part works
>
> great,
>
> > > > but I can't figure out when the remote host disconnects.
> > > >
> > > >I have the CVS version of php.
> > > >
> > > >Here is the function so far. The problem is at the end.
> > > >
> > > >
> > > >
> > > >function getdata ($host, $port, $data)
> > > >{
> > > >         /* well, the below comment would be true if i could get it
> > > > working! */
> > > >
> > > >         /* This function sends $data to $host:$port, then returns the
> > > > response
> > > >         * until connection is severed. Great for HTTP, but won't
>
> usually
>
> > > > work * too well in protocols where data needs to be analyzed, and
>
> replied
>
> > > > * to appropriatly, such as POP v3 */
> > > >
> > > >         // Create a socket
> > > >         $so = socket_create (AF_INET, SOCK_STREAM,
> > > > getprotobyname("TCP")); if ( !$so )
> > > >         {
> > > >                 exit("Could not create socket.\n");
> > > >         }
> > > >
> > > >         // Connect...
> > > >         $ec = socket_connect ($so, $host, $port);
> > > >         if ( $ec < 0 )
> > > >         {
> > > >                 exit ("ERROR $ec: ".socket_strerror($ec));
> > > >         }
> > > >
> > > >         /* Write $data to socket. The manual doesn't say what it
>
> returns,
>
> > > > but I'll
> > > >         * assume (even though it makes an ass out of you and me) that
>
> it
>
> > > > is the same
> > > >         * as socket_connect() because it wouldn't be logical to
> > > > return
>
> a
>
> > > >descriptor. */
> > > >         $ec = socket_write ( $so, $data, ( strlen($data) ));
> > > >         if ( $ec < 0 )
> > > >         {
> > > >                 exit ("ERROR $ec: ".socket_strerror($ec));
> > > >         }
> > > >         else
> > > >         {
> > > >                 /* PROBLEM IS HERE- what do I put instead of while (
>
> $x
>
> > > > == 0 )??? */
> > > >                 $x = 0;
> > > >                 while ( $x == 0 )
> > > >                 {
> > > >                         $buffer = socket_read ( $so, 1,
>
> PHP_BINARY_READ);
>
> > > >                         $string .= $buffer;
> > > >                 }
> > > >         }
> > > >
> > > >         // And (hopefully) return $string, for your viewing pleasure.
> > > >         return $string;
> > > >}
> > > >
> > > >--
> > > >PHP General Mailing List (http://www.php.net/)
> > > >To unsubscribe, visit: http://www.php.net/unsub.php

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

Reply via email to