How to display timer for cron job - php

I am currently working on a site that sumbit data from one table in the database to another table in the same database every 12th hour. I would like to display a timer that shows when the specific cron job is scheduled to run.
Maybe if this could be done in jquery to set up an automatic timer?
I hope someone know what to do to display this.

to do so You can do it by 2 ways as i know and there is the easy way and the hard way
1. the easy way
set the timer on your cron job and you can set same timer on a jquery clock there is a lot of them if you are using Chrome you can find them here on Chrome Store
Count Down Timer
2.The Hard way
is to access the Cpanel API and write your own Code to get the time
Cpanel API
That's what i came up with

Related

Loop through a large number of requests via PHP

I am developing a WordPress plugin that fetch user Instagram Profile info and store in database via WordPress wp_remote_get() function. A Corn job runs after every 24 hours that update the user's Instagram Info on daily basis. The problem is I've about 5000+ users and the script runs too long and the task never completed. Everything was working great when users quantity was under < 1000.
Which PHP settings in php.ini should I change to solve this issue? I've set max_execution_time to 0. Any other setting? Any suggestions?
I advice you to do the folowing
create more than one cron job which call same file
after update the user .. mark him as updated
do not update any user if he is marked as updated
make the updating function as transaction (finsh all or cancel all)
finally increase time out also good
Hard to make a valid recommendation without knowing your specific scenario, but I would change your code in the way that it visits instagram profile only when needed as opposed to for everyone via cron job. First, the info will be 'fresher', second, you'll avoid having the problem you're describing.
For instance, when a user visits their profile, a call is made to Instagram and data is pulled. You store the data in your database the same way as before, only with a timestamp. Also in the code, make sure that it doesn't pull data unless it's been 24 hours since the last refresh. Hope this helps.

Schedule alarm notification system php

I need some help regarding the implementation of the following alarm.. Here's the flow of the program, user login to the system and then they can click the hyperlink create schedule and then from there they can create schedules using the form. After which, user can choose to start this schedules that they created and they can allocate a timeframe to it. For eg, if the user assign the schedule to run at 2pm the system will have a pop up to notify and inform the user to run this schedule probably 15 mins before 2pm..
I would like to know what are the ways to implement this in php and if possible is there any reference i can use on the website? I've tried to find but apparently most scripts are paid etc.
I think you are looking for scheduler kind of thing, to do this in php
you can use scheduler for windows os
cron job for *nix based os
Yes the answer to this question is pretty much related to CRON job. Take a look at this answer
Execute Query on a Specific Date and Time
You need to write a PHP script that scans the db and sees for the user who should be notified (i.e their deadline has arrived). Run this script in the scheduler (maybe every 1 hour) and it will do the magic for you. Good luck with your notifications :)
No cron job is needed if you only notify user with popup on the web site, however, you will need a cronjob if you want to send emails.
You will have to store users schedules (possibly in a db table)
When the user logs in php should check if there's a task due in the schedules table for that user: if yes show the pop up.
You will need to create an ajax call (with users id) that will call a certain php (say ajax.php) file every minute. You can help yourself with jquery.
The ajax.php should check if there was a task due in the past. If yes it returns job details (as json or html, you chose) else it just returns that there are no jobs.
When the calling ajax code recieves an answer from ajax.php, it does nothing if the answer is that there are no jobs or displays a popup with job details recieved from ajax.php.
The user can dismiss the call (delete it from the schedules db table) snooze or reschedule it (update the due date in the schedules db table).
Don't forget about security especially in the ajax.php: it has to check if the user is logged in.
Only if you want to prompt non logged in users by email you will need to set up a cron jobs, that will ping the ajax.php file periodically.

How can I run an infinite loop on my website? (for a reminder/deadline announcer)

I'm building a website and i want to implement a reminder feature that alerts people if they have any projects or activities that are due or simply alert them of any timer they may have set. I have a clue about how i could do it with javascript's timer functions but i want it to run all the time and add reminders to a queue if the users are not online when the event occurs. Is there any way of doing this or do i have to use bash or python on the server?
Further explanation on how it's supposed to work:
- infinite loop checks for the time every X seconds, if there's a a reminder up between now and X seconds ago, print it to the user it belongs to - if the user is not online, put it in a file or something which is checked, when the user logs in, for any missed reminders.
another way i thought of is to use a local script (pyton or something) to check the database for reminders that are due, every X seconds, and write them in a file on the web server. then, server-side scripting will read it every X seconds and print the reminders to each logged account (and delete it at that point). This way no reminders are skipped even if the person it belongs to is logged out.
Any idea on how to do this more elegantly?
Use Cron Job instead and run your script with that to connect to your database and to do other tasks.
this functionality can be done with ajax and php. I wouldn't check the db when the user isn't online. I guess it is better to check reminders on login (unless you want to for example email them when they occur->then you need cron like mentioned in the other answers). you'll need to make a php script that checks which reminders have to be set and return them in an array/json. on login call this page. when user is logged in you can request your reminder php periodically/timer with ajax.
Having an infinite loop is by default bad design. PHP won't like it at all (memory). Javascript isn't ideal for the same reason too. Apart from that you don't want a javascript sleep to block your UI when waiting between tries.
Also, I wouldn't check notices when the user is not online. This is a useless way of using resources. Simply save the last time a user was online and display past notices that he hasn't seen before on login.
The cleanest solution in my book is some javascript library capable of eventdriven actions. An example of that is node.js. With events you don't need to check every N time but simply have an event triggered if some condition is met.

is there any way to save a timer in a database?

I'm a beginner.
I have a timer and progress bars for each item in a list. Bars progress sequentially. It runs whenever I load the page. I used cookies to make the timer stop from another page. But I want to keep the timer running even after closing the page.
I've thought of using a database to save the current time whenever someone accesses the page. So what I thought would happen is, the program will access the database whenever it opens the page then checks the saved time in the database and compare it to the current time to compute for the time elapsed and to be able to display how many progress bars should have finished progressing. But I don't know if this is a good idea. I bet not.
Is there any other way to implement this? Thank you. :D
Store the starttime or enddtime. Based on just that you can determine how much time is left.

After 30 seconds, update MYSQL database

I've been looking around here on SO and Googling, however I can't find anything that fits my description.
What I want to do is update the database if the page has not been refreshed after 30 seconds. I want to email a person with the contents of a form {submitted by a different user} (I can do that) IF the person has NOT visited the page (I can do that) within the last 30 seconds.
What I've tried to do is make the page that should be visited refresh every 30 seconds, and so I figured if I did something like after 31 seconds, edit the database (so if the refreshed page was not refreshed, the database editing would run).
I'm sorry if this sounds complicated, there's probably a better way to do this, but I'm not sure how.
The bigger picture is I'm trying to make a 'on-duty' sort of thing, so that if the person is not actively looking at the page, they will get emailed with whatever the contents of the form is. The page will contain a table of all the entered form results.
You could update the database by creating a record with a timestamp every time the user refreshes the page. Then, you can have a PHP worker that looks regularely in the database if the timestamp is older than 30 seconds, and starts the e-mail.
I can't provide php solution for the server-side part of the job. But basically you need to set up javascript timer (eg. jquery timeout) and after 30seconds do the ajax call that will do what you want on the server (save something to db, send email and so on).
I hope I got your point and my advice will help you somehow.
maybe use an AJAX call every 30 secs based on the setTimeout javascript function?
http://www.w3schools.com/js/js_timing.asp
function timedCount()
{
# ajax call
t=setTimeout("timedCount()",30000);
}
I would suggest using javascript like this:
window.setTimeout("location.reload(true);", 3000);
This is of course if you desperately need to reload, but the user will obviously be mad that you reload the window for him.

Categories