Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imap_open with timeout #90

Closed
skynet opened this issue Jul 15, 2015 · 7 comments
Closed

imap_open with timeout #90

skynet opened this issue Jul 15, 2015 · 7 comments

Comments

@skynet
Copy link

skynet commented Jul 15, 2015

Would it be possible to setup a timeout on

$connection = $server->authenticate('my_username', 'my_password');

Sometimes (and no idea why) it takes too long to authenticate and I'd rather retry. How do I stop (and debug) php when doing imap_open. Code snippet from https://github.com/ddeboer/imap/blob/master/src/Server.php below:

    public function authenticate($username, $password)
    {
        // Wrap imap_open, which gives notices instead of exceptions
        set_error_handler(
            function ($nr, $message) use ($username) {
                throw new AuthenticationFailedException($username, $message);
            }
        );

        $resource = imap_open(
            $this->getServerString(),
            $username,
            $password,
            null,
            1,
            $this->parameters
        );

        if (false === $resource) {
            throw new AuthenticationFailedException($username);
        }

        restore_error_handler();

        $check = imap_check($resource);
        $mailbox = $check->Mailbox;
        $this->connection = substr($mailbox, 0, strpos($mailbox, '}')+1);

        // These are necessary to get rid of PHP throwing IMAP errors
        imap_errors();
        imap_alerts();

        return new Connection($resource, $this->connection);
    }
@Padrio
Copy link

Padrio commented Jul 15, 2015

I have the Same Problem (sometimes the authentification takes too Long)

Would vote for it (if the Library has this feature)

Am 15.07.2015 um 06:28 schrieb Ionel Roiban notifications@github.com:

Would it be possible to setup a timeout on

$connection = $server->authenticate('my_username', 'my_password');
Sometimes (and no idea why) it takes too long to authenticate and I'd rather retry. How do I stop (and debug) php when doing imap_open. Code snippet from /ddeboer/imap/blob/master/src/Server.php below:

public function authenticate($username, $password)
{
    // Wrap imap_open, which gives notices instead of exceptions
    set_error_handler(
        function ($nr, $message) use ($username) {
            throw new AuthenticationFailedException($username, $message);
        }
    );

    $resource = imap_open(
        $this->getServerString(),
        $username,
        $password,
        null,
        1,
        $this->parameters
    );

    if (false === $resource) {
        throw new AuthenticationFailedException($username);
    }

    restore_error_handler();

    $check = imap_check($resource);
    $mailbox = $check->Mailbox;
    $this->connection = substr($mailbox, 0, strpos($mailbox, '}')+1);

    // These are necessary to get rid of PHP throwing IMAP errors
    imap_errors();
    imap_alerts();

    return new Connection($resource, $this->connection);
}


Reply to this email directly or view it on GitHub.

@ddeboer
Copy link
Owner

ddeboer commented Jul 15, 2015

It seems this can be done with imap_timeout. Do you feel like opening a PR?

@Padrio
Copy link

Padrio commented Jul 15, 2015

Maybe i will create one in a few hours.

Am 15.07.2015 um 20:39 schrieb David de Boer notifications@github.com:

It seems this can be done with imap_timeout. Do you feel like opening a PR?


Reply to this email directly or view it on GitHub.

@ddeboer
Copy link
Owner

ddeboer commented Jul 15, 2015

Cool!

On Wed, Jul 15, 2015 at 8:42 PM, Pascal Krason notifications@github.com
wrote:

Maybe i will create one in a few hours.

Am 15.07.2015 um 20:39 schrieb David de Boer notifications@github.com:

It seems this can be done with imap_timeout. Do you feel like opening a PR?


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub:
#90 (comment)

@nicosabio2016-zz
Copy link

Hi do you already have a solution for this? I'm having the same problem for this.

@skynet
Copy link
Author

skynet commented Feb 21, 2016

no solution other than to monitor the process and stop if trying to connect runs for too long

@Slamdunk
Copy link
Collaborator

Slamdunk commented Oct 4, 2017

Hi, to me this doesn't seem an issue related to the library, and I can't figure out how we can help to face it.
As said, you can try using imap_timeout which sets global configuration for all imap functions, and so you don't have to wait we implement it to use it.

@Slamdunk Slamdunk closed this as completed Oct 4, 2017
This was referenced Nov 6, 2017
Slamdunk added a commit that referenced this issue Nov 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants