1

I'm using the PHP Imap Library along with Ajax to display search results from within emails. The main problem I am finding is that providers (Hotmail in particular) will cut off connection after 6 or 7 connections in close proximity of time.

Instead of imap_connect() in each script, I'd like to connect once and then continuously display information with ajax. I just have no idea how to do this. The problem is that I need to spit out data through the ajax. Is there any way to return information without ending the PHP program through jquery?

I could also potentially do this if I pass the imap connection variable $connection to the php query instead of calling it, but unsure how to pass it. Here's how I'm currently passing the variables.

    var dataString='email=<?php echo $email_address; ?>&connection=<?php echo $connection; ?>&password=<?php echo $password; ?>&server=<?php echo $server;?>&daysago='+daysago+'&num='+num;
    $.ajax({
       type: "POST",
    url: "fastsearch.php",
    data: dataString,
    success: function(msg){

Link to Imap Connect (and general php imap library): http://php.net/manual/en/function.imap-open.php

1 Answer 1

2

I've done "socket emulation" programming in PHP and jQuery in the past, which is a sort of COMET based approach to keep long connections.

This is really a shining example of where Node.js is favorable to web application development as for the easily installable and usable Socket.io library.

Node.js aside, you have a few options, forking a process that keeps your connections alive and persistent, not connecting live every time someone signs in (use an async task manager like celery), and using a COMET approach which is basically an infinite while loop that constantly spits out data to the client side. The latter would keep a single connection open, but would also be highly unstable, non-performant, and by using PHP the wrong tool for the job.

I'd urge you to reconsider your PHP dependency for this specific task, and instead move in favor to a library that was designed for this specific server push/persistence.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.