Page 1 of 1

Multiuser PHP5 app with AJAX - what pattern?

Posted: Sat Jun 14, 2008 10:39 am
by vargadanis
Hi!

I am writing a PHP5 app which is to server multiple user at one time. I want to use AJAX for the UI. I also need to use certain imap functions. I have class in which I save the imap_stream as the following:

Code: Select all

class A{
  protected _imap_connection;
  protected function connectToServer($host, ...){
    /*
     *  functions to handle connection
     */
    $this->_imap_connection = $conn; //conn is the var for imap_open;
  }
  protected function doSth(){
    // sth which needs info on imap_connection eg: imap_fetchbody
  }
}
 
This works great when I am trzing to call function from within the class. However when I call the functions from outside this function it does not work. Here is what I ment:

Code: Select all

class B extends A{
  public function __construct(){ 
    $this->doSth();
  }
}
That returns and error that no valid imap resource is avaliable. So what I am supposed to do? I tried useing $_SESSION to store info on imap connections but session is not suitable for that.

Re: Multiuser PHP5 app with AJAX - what pattern?

Posted: Sun Jun 15, 2008 1:32 am
by vargadanis
Alright... It is funny. It seems that I have no luck with the apps I am trying to dev. I had 3 topics or so and none of them were answered. :) lol This is sooo mee

Re: Multiuser PHP5 app with AJAX - what pattern?

Posted: Sun Jun 15, 2008 2:33 am
by John Cartwright
imap_open() returns a rescource, and resources cannot be saved outside of the current request. You'll need to open a new connection on each request.

Also, next time please wait the full 24 hours before bumping.

Re: Multiuser PHP5 app with AJAX - what pattern?

Posted: Wed Jun 18, 2008 3:15 am
by vargadanis
Rgr that... Sorry about that... And thanx for the help. :lol:

Re: Multiuser PHP5 app with AJAX - what pattern?

Posted: Fri Jun 20, 2008 2:29 am
by vargadanis
I got this from a maillist. Thought it can be interesting:
On Thu, 19 Jun 2008, Mark Bishop wrote:

Is it possible to have persistent imap connections? In every operation in IMP I see a login and then a logout in my log files. If this is a stupid question, my apologies.


Not within Horde/IMP. You could use an IMAP proxy daemon to cache open connections though. I'm not sure what people use these days, but I saw one called "imapproxy" being used years ago.


http://www.imapproxy.org/

michael