Results 1 to 3 of 3

Thread: Read all data from socket

  1. #1

    Thread Starter
    Addicted Member señorbadger's Avatar
    Join Date
    Oct 2003
    Location
    Mud pools of wellingborough
    Posts
    193

    Read all data from socket

    hello i am connecting to a POP3 server and want to read all the data recived into a variable

    as you prolly know fgets() only retrives 1 line of data so i made this loop, but when it executes it hits an infinate loop

    PHP Code:
    while (!feof ($fd)) {

        
    $buffer fgets($fd4096);

        echo 
    $buffer;


    obiously not good

    how can i do this since it says socket_read() is not defined on my hosting server but fsockopen() works fine

    thanks for ya help

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    feof() will not return true until the connection has been closed by either the client or the server.

    In the case of the POP3 protocol you would terminate the connection by sending it the QUIT command. You'll then be able to read all the data off the socket using your loop.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    POP3 servers tell you the end of the information by sending a period '.' on its own. I think i posted something abot using POP3 with php, ill just take a look.

    [EDIT]

    PHP Code:
    while(!($msg[0]=='.' && strlen($msg)==3)){
        
    $msg fgets($socket_handle,1024);

    That will check for the deliminator. Which will let you carry on with your script after the information has been sent to your script.

    [/EDIT]
    Last edited by john tindell; Sep 15th, 2004 at 09:34 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width