Solved

php feof fwrite

Posted on 2007-11-17
3
820 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 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