I have a PHP redirect page to track clicks on links. Basically it does:
- get url from $_GET - connect to database - create row for url, or update with 1 hit if it exists - redirect browser to url using Location: header
I was wondering if it’s possible to send the redirect to the client first, so it can get on with it’s job, and then log the click. Would simply switching things around work?
You can do this:
$_GETLocation:headerflush()This will not necessarily cause the browser to go on its way immediately, since your connection is still being held open and what the browser does about that is up to it, but (barring conditions that cause
flush()to not work) it will at least get theLocation:header out to the browser so it can do the redirect if it likes.If that’s not good enough, I’d recommend dumping your data to per-minute or per-second files that a script then picks up for postprocessing into the database. If that’s not good enough, you can play with
pcntl_fork(); this is an extremely hairy thing to do under Apache SAPI.