Closed (fixed)
Project:
DrupalChat
Version:
7.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
7 Dec 2011 at 21:08 UTC
Updated:
6 Feb 2012 at 19:20 UTC
Hello,
do {
sleep(3);
$buddylist_online = _drupalchat_buddylist_online($buddylist);
//$message_count = db_query('SELECT COUNT(*) FROM {drupalchat_msg} m INNER JOIN {users} u ON m.uid1 = u.uid WHERE m.uid2 = :m.uid2 AND m.timestamp > :m.timestamp', array(':m.uid2' => $user->uid, ':m.timestamp' => $last_timestamp))->fetchField();
$message_count = db_query(' SELECT COUNT(*)
FROM {drupalchat_msg} m
INNER JOIN {users} u ON m.uid1 = u.uid
WHERE m.uid2 = :uid2
AND m.timestamp > :timestamp', array(':uid2' => $user->uid, ':timestamp' => $last_timestamp))->fetchField();
_drupalchat_touch_user($user->uid);
module_invoke_all('drupalchat_longpoll'); // Long poll hook
} while (((REQUEST_TIME - $initial_time) < (ini_get('max_execution_time') - 5)) && ($message_count == 0) && (_drupalchat_buddylist_diff($buddylist_online_old, $buddylist_online)));
1. Wanted to bring to your attention that sleep(3) in the polling code does not count as execution_time on linux.
2. The code above, per my tests, will never really break out from exhausting the max_execution_time because of point #1 and because $initial_time never changes. I've modified it as follows:
_drupalchat_touch_user($user->uid);
module_invoke_all('drupalchat_longpoll'); // Long poll hook
$initial_time -= 3;
Thoughts?
Comments
Comment #1
darklrd commentedThanks a lot for bringing this up. I am sorry but I couldn't get your point #1. Could you please elaborate? Thanks.
Comment #2
darklrd commentedDo you mean to say that REQUEST_TIME and $initial_time will always remain same?
Comment #3
Ashraf Amayreh commentedIn general, sleep doesn't count as part of the execution time on Linux servers. So let's assume that you have max_execution_time set to 30 and you try this code:
You will get a Done because sleep is not counted as part of the execution time :) What I did to fix this is simply subtract 3 seconds from the $initial_time after every sleep:
Hope this is the correct fix for it.
Comment #4
Ashraf Amayreh commentedRight. That's what I'm saying. They will of course vary in some microseconds, but the function that you expect will finish in 30 secs will actually take... probably a year to finish without timing out :D
Comment #5
Ashraf Amayreh commentedOr to illustrate it even more:
Comment #6
darklrd commentedOMG! This is scary! I didn't know this. Thanks a lot for pointing this out :)
I will commit it soon. Thanks again!
Comment #7
Ashraf Amayreh commentedAnytime. If you do insist on helping out, then check out my just created issue on chat room :) Why are the access rules so screwed up for chat nodes?
http://drupal.org/node/1413294
Comment #8
darklrd commentedHi,
I tested this again. sleep() is counted as part of the execution time. The problem was REQUEST_TIME variable. It doesn't give the current time. I have fixed the issue. Thanks a lot for your help :)