Solved

php feof fwrite

Posted on 2007-11-17
3
816 Views
Last Modified: 2008-08-17
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

0
Comment
Question by:tonelm54
  • 2
3 Comments
 
LVL 20

Expert Comment

by:steelseth12
ID: 20306083
$handle = fopen("c:\\test\\51.eml", 'a');
   
       fwrite($popOpen,"RETR 51\n");      
   
       while (!feof($popOpen))
          {
          $buffer .= fgets($popOpen, 4096);
         
          }
             
       fwrite($handle,$buffer);
   
       fclose($handle);
0
 

Author Comment

by:tonelm54
ID: 20307187
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!
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 20308298
If $popOpen above is a valid resource then the code shoud work just fine.
Can you post the rest of your code ?

Here is some example code i found that can be of help to you.

http://www.weberdev.com/get_example-4015.html

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question