Solved

php feof fwrite

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
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 …

863 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

25 Experts available now in Live!

Get 1:1 Help Now