internet explorer - How to redirect IE in php without die()? -


i'm working on site whith external webshop this:

$webshopurl = "webshop.com/something/?id=" . $transaction_id; //and other parameters header ( "connection: close" ); header ( "location: " . $webshopurl ); header ( "content-length: " . $length ); $response= getresponse($transaction id /*and other stuff*/); 

getresponse() contains lopp keeps polling webshop see how transaction went, , reacts accordingly if transaction finished, or exits timeout after 10 minutes. on browser works fine, browser goes webshop, user buys , once transaction on polling loop gets info , whatever does. ie won't redirect until php stops running, loop can't possibly handle webshop transactions. tried manually entering webshop url browser, , worked fine. didn't write system, maintain it, i'd rather refrain complete overhaul of system.

edit: tried using javascript , and html meta redirect, work after php stopped running

the direct answer question need close http connection between php program , browser.

doing manually achieved sending following 2 headers:

connection: close content-length: n (n = size of output in bytes ) 

...followed flushing output cache.

the code this:

// send headers tell browser close connection header("content-length: $contentsize"); header('connection: close');  // flush output ob_end_flush(); ob_flush(); flush();  // .... php code can continue without browser caring it. 

as you'll notice above, need know how big output you've sent -- important; browsers can react badly if give them incorrect value here. can keep track of using output buffer (ob_start(), ob_flush()), , checking size of ob_get_length(). not ideal, best solution. of course, if you're doing redirect, may not outputting body, in case, give size of zero.

however...

i caution against doing kind of thing. problem here if program has error causes never stop running or infinite loop, etc, doing make kind of bug very difficult track down. may not know until server starts slowing down or refusing connections no apparent reason.

i suggest better off handling long-term processing in entirely separate process thread. way i'd polling using small short-lived php program fired cron-job. keep running program on , on @ set interval behind scenes, no connection end user or browser.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -