开发者

How to stop loading iframe and php process in it

I got a script, which checks mail in my own Webmail. And I want to add cancel button. So, if user sees, that it will take too long to check all mail (he has 100 new mails), he can cancel proccess (for example, on 31st mail).

I run this script in iframe:

public function checkEmailAction() {
    set_time_limit(0);
    while (@ob_end_flush()) {
    }
    ob_implicit_flush(1);

    $strError = '';
    echo "";

    $accountId = Zend_Json::decode($this->_getParam('account_id'));
    if (!$this->mail_account->hasAccessToAccount($accountId)) {
        $strError = 'Insufficient access rights';
    }

    if (empty($strError)) {
        try {
            $this->mail->sync($accountId);
        } catch (MailException $e) {
            Mail_LoaderDispatcher::change('Error. ', 100, null, true);
            if($e->getMessage() != "Can't connect to email account.") {
            Zend_Registry::get('log')->debugErrorToFile('Mail Error: ' . $e, '', 'mail');
        }
        }
    } else {
        Mail_LoaderDispatcher::change($strError, 100, null, true);
    }

    echo "";
    exit();
}

On cancel button click event I added such code, which destroys iframe, but doesn`t stop php process:

var ifr=$('#mail_iframe_check_email');
ifr.remove();

But the php script keeps working and all mails are downloaded :(

Maybe, there is some way on cancel butt开发者_StackOverflowon click send some param (via Cookie or Get) to iframe and stop php script from running?


The only way to stop the PHP script from running, short of manual intervention on the serverside, is to kill the script from console. However, you can write the functionality yourself if you have access to the PHP script's source.


Edit:

What you're evidently going to have to do is write your script to download a few mails at a time, say five or ten. Have one script invoked from iFrame download these mails, and then when it's done return some HTML and AJAX that:

  1. checks the parent frame for a hidden field, and if that hidden field is set to 1,
  2. reloads itself to process the next 5-10 mails.

Then you'd change the Cancel button so that it sets the hidden field to 0, and the script terminates instead of continuing on the next cycle.

You could set the number of mails processed at once to a lower number, say 2 or 1, and this will make the cancel button more responsive in exchange for using more HTTP requests.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜