Solved

php feof fwrite

Posted on 2007-11-17
3
808 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

759 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now