davemo Posted February 13 Share Posted February 13 Hello there. I need your help. I don't know how to do it. 😰 First: I need to make automatic updating mysql (I need something update in mysql for all users every 24 hours) and if possible, show them remaining time. Second: I need make timer, if user click on something, he must wait (for example: User click on button, then must wait 1 minute before code start) but I need the timer showing remaining time and if refresh page, still continue with remaining time, no start new timer. (for example: user must wait 1 minute, he waiting 10seconds, refresh page and continue with remaining time. Or user logout, the 1 minute timer still continues and when he log in after 1 or 2 minute or any other time after 1min, the timer will be finished.) Is this possible? If yes, can you help me with this, please? Many thanks! Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 13 Share Posted February 13 And what have you attempted to do so far? We help. We don't write. Quote Link to comment Share on other sites More sharing options...
Phi11W Posted February 14 Share Posted February 14 15 hours ago, davemo said: I need something update in mysql for all users every 24 hours This is almost always the wrong way to do things. You cannot guarantee that this update process will run every, single day. This is Technology - stuff happens. Updating every record is a lot of [unnecessary] work for your database to do and will, almost certainly, lock the entire table, causing other issues. 15 hours ago, davemo said: if possible, show them remaining time Showing stuff to Users is not the database's job. You'll write an Application that the Users interact with and that will show them your "remaining time". 15 hours ago, davemo said: if user click on something, he must wait (for example) 1 minute before code start I'm sorry, but why? Users these days want instant responses, not arbitrary and artificially-enforced delays. If you are interested in a particular date & time, then work out when that is and store that. You never need to change it, "in bulk" or at all, Your application can calculate how long it is until "Real Time" catches up with it and show that duration to the User, no matter what they do in the meantime (refreshing, logging off-and-on again, etc. ), and You can easily tell once you have reached it in a SQL query. Keep it Simple ... Regards, Phill W. 1 Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 14 Share Posted February 14 I am in agreement with @Phi11W above. There are scenarios where some things need to be processed on a schedule, but that is not always the case. So, it would be helpful to know what you are wanting to "happen" every night and what will "happen" after the one minute when the user clicks a button. Depending on what you are trying to do the best solution can be different. But one of the preferred way to initiate things on a schedule is with a CRON job which is a scheduled task within a Linux server (which is where most PHP implementations are hosted). If you are hosting your application with a provider they likely have a custom interface for setting these up. You would start by creating a PHP file that will run a process (your nightly process or the process to run after one minute of the button click). For the nightly process you you set up the CRON job to run at a specific time each night. You should set up a notification to be sent and report if the process passed or failed. As for the process to run 1 minute after a button click someone may know a better process, but the only way I can think to do that would be to have a scheduled process that runs every 10 seconds (or some time that you specify). When a user clicks the button, you would add a record to the DB for the time they clicked it and a flag to indicate it had not been completed. Then every 10 seconds when the process runs, check the DB for any unprocessed records and "process them" and update the completed flag accordingly. From the user perspective you can always display the time to execute based on the timestamp that was added to the DB. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.