Multiuser PHP5 app with AJAX - what pattern?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Multiuser PHP5 app with AJAX - what pattern?

Post 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.
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: Multiuser PHP5 app with AJAX - what pattern?

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Multiuser PHP5 app with AJAX - what pattern?

Post 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.
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: Multiuser PHP5 app with AJAX - what pattern?

Post by vargadanis »

Rgr that... Sorry about that... And thanx for the help. :lol:
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: Multiuser PHP5 app with AJAX - what pattern?

Post 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
Post Reply