/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Comet with PHP on Apache

I’m developing a COMET based program using the Multipart-x-mixed-replace method and I’m having an issue. I have a while(1) loop in place and the first time I run it, it’s fine. If I close out of the window and go back into it, it doesn’t work. The issue I’m seeing is that apache/PHP isn’t closing that script and it continues to run. Any ideas on how to get it stop when the window is closed?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SyCoJul 14.2008 — Once the script starts closing the browser can't stop it. You could add an exit condition to the script to stop it afte x number of loops. If it runs the first time it should run again unless the loop is endless and eating up resources? Your issue sounds more like a scripting error than the Apache set up but without knowing a lot more there's no way to guess any further. Your script shouldn't be running endlessly unless that's what you've told it to do.
Copy linkTweet thisAlerts:
@ellisglauthorJul 15.2008 — I figured it out. Basically, I start the COMET script with a $_GET argument of the user's ID. Then, I have the script get the pid (getmypid()). After I have the PID I update the DB that contains the the user's ID with the PID. Then I have a javascript that detects when the window is closed and do an ajax call to another script with a $_GET argument of the user's id. That script then pulls the PID for that script then runs exec('kill '.$pid);

It could be made a bit more secure thou.
×

Success!

Help @ellisgl spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...