The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Small Error Gap Which Is Big
Discuss Small Error Gap Which Is Big in the PHP Development forum on Dev Shed. Small Error Gap Which Is Big PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 6th, 2012, 09:51 AM
|
|
Contributing User
|
|
Join Date: Sep 2011
Posts: 189
Time spent in forums: 15 h 55 m 34 sec
Reputation Power: 2
|
|
|
Small Error Gap Which Is Big
Hi, my site requires users to complete a certain task on the site everyday before the end of the day 23:59:59 (don't worry about timezones or the task)
The task has a $today_status (complete or incomplete)
I have a cron that runs at the start of the day (00:00:01) to do 2 things:
01 - check if all tasks were completed yesterday (check for all tasks that are still incomplete)
02 - reset all of yesterdays tasks back to incomplete so the user can start the task again today (for the new day)
Each task has a count down timer displayed next to it so that the user can see one of the following two timers:
A (IF $today_status = incomplete) - the time they have left to complete the task (counting down to the end of the day)
B (IF $today_status = complete) - the time they have to wait before they can complete the second task (counting down to the end of the day)
I have 2 small problems that are related:
The crons runs as soon as it turns into a new day at 00:00:01 however the cron not might finish processing all of the tasks until 00:07:19 so there is a 7 min error gap... this could increase as more users join.
So, if the user has completed the task for the previous day, and then views the task at 00:03:27 the next day... $today_status could still be 'completed' as the cron might not have processed it for the previous day yet... and there for the timer will say
23:54:33
(time left to wait before you can start the next task)
It will say the above because it is still in 'complete' status... however the user just logged in early so they could complete today's task early BUT the site is telling them otherwise... it is telling them they have to wait until tomorrow to complete the next task...
I hope i am explaining this correctly and thank you so much if you have bothered to read down this far... any help will be greatly appreciated... thanks in advance
|

December 6th, 2012, 09:59 AM
|
|
|
|
OK, so what does any of this have to do with PHP?
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.
|

December 6th, 2012, 10:03 AM
|
|
Contributing User
|
|
Join Date: Sep 2011
Posts: 189
Time spent in forums: 15 h 55 m 34 sec
Reputation Power: 2
|
|
|
Thank you for reading...
To answer your question... hopefully someone who programs in PHP can advise on a better solution or fix... in "PHP"
|

December 6th, 2012, 10:19 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
Store the most recent timestamp the task was complete. That way your code can know if "today's" task was actually completed today, since you'll have the timestamp of that user's task to compare to the current time.
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|

December 6th, 2012, 10:19 AM
|
|
|
|
I see no PHP to fix or advise. However, I can give you a general suggestion. When the cron job starts set a flag somewhere that your page can read. If set have your page output a notice, rather than task data, indicating the data is being updated and to please try later. Once the cron job finishes clear that flag.
|

December 7th, 2012, 12:04 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 2
Time spent in forums: 45 m 21 sec
Warnings Level: 15
Number of bans: 1
Reputation Power: 0
|
|
|
I can only think of a workaround. As the cron will be more and more slow, then you could add a "last_cron_date" field that will show you when have the cron last time fixed the given task. Thus in the UI you will check if the task has been passed by the cron TODAY, and if so display the remaininng. If the cron has not yet reached this task, its date field will still be yesterday, and you can handle this properly - either say "this task is being currently handled", or allow it to be handled or whatever you decide to do for the handling time gap.
Last edited by requinix : December 7th, 2012 at 01:09 AM.
Reason: removed spam
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|