Once Again I Failed To Fail

November 25, 2006 on 3:26 pm | In PHP | 1 Comment

After my first failure to fail, now I hold the Zend PHP 5 Certification, it was a tough day day for me, it was like:
6:30
I started the second Mock-Up Exam, I passed it, but my results were worse than the first, “OK Ala’a, don’t panic, you might just be tired”, So I went took a bath a done some stuff.
9:30
My colleague, who’s supposed to take the exam with me, came online, and he wanted to talk the Mock-Up exam.

Me: but i don’t think that you have enough time left.
He: Do you think so.
Me: it’s 9:30 …
He: Yeah I noticed that.
Me: you have an hour and a half till the test.
Me: Unless you do it fast …
He: do u suggest to review the book! or take the test ??
Me: no take the test, that’s better.

10:05
I’m ready to leave, I closed the computer, and went to the door, I put my hands in my pocket, the keys are not there. “Damn, where did the keys go” I thought. I started looking around, I was starting to panic. “Don’t panic, you’ll find them” I thought.
I started searching, that lasted for 30 seconds, and then I panicked, I started throwing everything, and I found the keys, I don’t want to know how did they get there, I was glad I found them.

10:45
I reached the test center, everything went smoothly.

11:00
My colleague and I started the test.

11:40
I’ve answered everything, but I’m not sure about anything, I hate tests, now I have to click on the “End Exam” button. I clicked on it, and a confirmation message popped-up, I was so unsure, I started moving the message all over the screen, until I had the guts to press “OK”. And my longest period of time in this day was then.
“Processing ….”
“What if I failed”
“Processing …”
“I should’ve answered something else”
“Processing …”
“I should’ve postponed the test”
“Congratulations, you passed”
“Yes!!!!” I screamed.
“Congratulations …”, My colleague said.
“Thanks, Hope the best for you”, I said.
“Pray for me”, he said.
“I will”, I replied.

12:00
My Colleague gets out of the test room, …., He passed.

WoooooooooooooooW, I’m glad that everything went OK today.

Playing with PEAR Net_IMAP

November 22, 2006 on 12:54 am | In PHP | No Comments

when it comes to IMAP programming, you should be very careful about IMAP commands you are issuing, an unneeded call can make your page much slower, that’s why usually IMAP Developers avoid programming with the php IMAP functions, yes they are written in C (c-client), but they don’t give you the commands you want exactly, so usually you would go for native IMAP (i.e. writing commands to a socket, and parsing the output).
Parsing is never an easy job, lot’s of cases and lot’s of bugs can appear, PEAR have a nice library called Net_IMAP, but of course, it doesn’t give you the freedom you need, so I use the IMAPProtocol class from it, as what I need is parsing only, I know the command, I just want to issue them, and to get them parsed.
for example to fetch the headers of a message

<?php
  $imap->cmdConnect($mailhost,$mailport);
  $imap->cmdLogin(”$username@$domainname” , $password);
  $imap->cmdSelect($mailbox);
  $msgHeader = $imap->cmdUidFetch($message_uid,’BODY[HEADER]‘);
  $imap->cmdLogout();
?>

That looks fine, but Imagine this case, you have to sort the mailbox according to the From header, well of course you can do something like the code above, i.e. fetch the headers of all the messages, and parse for the From header, and sort accordingly, but the headers of messages are not a small part, you can have 25 lines for each message while you only need 1, which would slow down your page. if you have some experience with IMAP you would know that you code do this with a command like

A0001 FETCH 1:* (uid body.peek[header.fields (From)])

OK if you try this on IMAPProtocol, in the standard way, i.e $imap->cmdFetch(”1:*”,”(uid body.peek[header.fields (From)])”);
you would get lots of errors telling you that it’s not supported, so what should you do????
well here you have to do parsing yourself, but how can you do that, take a look at the code below:

<?php
  $imap->_getCmdId();
  $imap->_putCMD($cmdid,’FETCH 1:* (uid body.peek[header.fields (From)])’);
  $nsarray=explode(”\n”,$imap->_getRawResponse( $cmdid ));
  foreach ($nsarray as $line) {
    if(strstr($line,”FETCH (UID “)) {
      $UID_array[] = (int) (substr($line,strpos($line,”UID “) + 4));
    }
    if(strstr($line,”From: “)) {
      $msgs_to=trim(strtolower(str_replace(”From: “,”",$line)));
      $from_array[]=$msgs_to;
    }
  }
?>

Why would I do that, well My page is full of IMAPProtocol code, and I want to add the feature of sorting, I can’t just drop the whole page, and I want to make the best performance I can, in the less time I can.
Hope it was useful.


Digg!

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^