Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

php feof fwrite

I have written some code, which collects emails through a pop3 server, Got it working, however fails to read big emails.

From what Ive read I need to use a while loop, but when I read just 1 email, I get timeout error. In my working example takes milliseconds to pull the email, and about 3 seconds to collect 110 emails.

Do I need to tell it to go to the next line and read?

Tony
//Very Slow!!!
     $handle = fopen("c:\\test\\51.eml", 'a');
     fwrite($popOpen,"RETR 51\n");	
     while (!feof($popOpen)) 
          {
          $buffer = fgets($popOpen, 4096);
          fwrite($handle,fread($popOpen,8192));
          }
     fclose($handle);
 
//Works
     $handle = fopen("c:\\test\\51.eml" . $counter . ".eml", 'a');
     fwrite($popOpen,"RETR " . $counter . "\n");	
     fwrite($handle,fread($popOpen,8192));
     fclose($handle);

Open in new window

Avatar of steelseth12
steelseth12
Flag of Cyprus image

$handle = fopen("c:\\test\\51.eml", 'a');
   
       fwrite($popOpen,"RETR 51\n");      
   
       while (!feof($popOpen))
          {
          $buffer .= fgets($popOpen, 4096);
         
          }
             
       fwrite($handle,$buffer);
   
       fclose($handle);
Avatar of tonelm54
tonelm54

ASKER

Nope still the same problem.

During debug it seems to enter the while loop, go round several times, then stop, and just hang!

I would suggest that it isnt able to see the last 4096 and maybe less, but as I dont know too much about this, cant really suggest it.

HELP!!! I dont  have much hair left, lol!
ASKER CERTIFIED SOLUTION
Avatar of steelseth12
steelseth12
Flag of Cyprus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial