2

I have a mailbox option in my CRM, in the mailbox everything working fine, PHP IMAP functions fetching data is take to much of time, initially it takes 57 second for per request, i have note the loading time log for each and every IMAP function, there imap_open() function takes 16 seconds, after that i use only one imap_open() function for per controller, if i use another controller i need to use imap_open() function again then it will take the same timing, so i have decide to take a imap_open() function's return value to store one session value and pass the return stream parameter in every imap function instead of imap_open() Function return stream, it doesn't work finely, because imap_open() function return value is 'Resource id #61' if i pass this value for imap stream parameter it fail to retrieve my imap function

Now, i need a help how to get a exact stream value of imap_open() function

<?php  
    $start_time = date('H:i:s');  
    $data['per_page'] = 50; //$this->config->item("per_page");
    $data['start'] =  1;
    $data['default_email'] = $this->input->post('email_id');
    $email_details = $this->Mailbox_model->email_by_id($data['default_email']);

    $imap_host  = $email_details->smtp_host.':993'; // IMAP host address
    $imap_flags = "/imap/ssl/novalidate-cert"; // IMAP Flags
    $imap_user  = $email_details->email_ID; // IMAP username
    $imap_pass  = decryptthis($email_details->password, 'Rajexim2020'); // IMAP password
    $ima_time_1s = date('H:i:s');
    $imap_open_start = date('H:i:s');
    if ($email_details->imap_stream == '') {
      $inbox = @imap_open("{".$imap_host.$imap_flags."}INBOX", $imap_user, $imap_pass)or die('Cannot connect to Gmail: ' . imap_last_error());
      $update_stream_to_db = $this->Mailbox_model->update_stream_to_db($email_details->email_detail_id,$inbox);
    }
    else {
      $inbox = $email_details->imap_stream;
    }



    $imap_open_end = date('H:i:s');
    $data['tot_mail_list_count'] = imap_all_inbox_mail_count($inbox);

?>
Jegan S
  • 27
  • 7

1 Answers1

1

The imap open function returns a handle to work with a resource. This resourse cannot be show or visualized, that is why you see 'Resource id #61'. See https://www.php.net/manual/en/language.types.resource.php for more information about recources.

In order to get the passed imap stream to work you need to re-open the stream, this could be done by calling the imap_reopen function.

See https://www.php.net/manual/en/function.imap-open.php for more information about the imap-reopen function.