I have a page with clients and with ajax im information is loaded on whether they send us an email or not.
The code is as follows:
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; $username = 'email'; $password = 'password'; $this->session->data['imap_inbox'] = $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); foreach($customers as $customer){ $emails = imap_search($inbox, 'FROM ' . $email);
But on one page there are about 20-30 clients, so it sometimes takes about 10-20 seconds to complete this process, and I could not optimize the process.
But when the client tries to reload the page, it is still waiting for imap_search finish, so it may take 20 seconds to reload before reloading the page.
I tried beforeunload ajax using the beforeunload function and closing imap , but this does not work.
My code is:
Ajax:
$(window).bind('beforeunload',function(){ imap_email.abort();
PHP:
if($this->request->get['kill'] == '1'){ imap_close($this->session->data['imap_inbox']); unset($this->session->data['imap_inbox']); $kill == 1; exit; }
But even if ajax interrupted and imap_close is called while holding the imap_open variable, it still takes 10-20 seconds to reload the page, so I assume that imap was not closed.
How to close imap so that the page can reload immediately?
javascript jquery ajax php imap
Jtc
source share