I have the php project for user can register and buy the hours to listen music or video, the not used of 50% hours have to rollover to next month, I wanted to automate this process when user complete one month I have to check their usage and process the rollover using php. I have following user details on DB, Signed-up date with time and usage and hours they purchased and used hours. I want to do it once in a month for each customer.
Is it possible using cron jobs? I don't have any idea to do this.
Not sure if this is the right approach but I've been running such kind of scripts when a user logs into his account.
For example.
You can do something like on successful login request by the user
if(date of buying hours has crossed the specified limit) /here you can check for expiry date/
{ // run your script here
}
else{}
just a suggestion!
You don't need to update all of the records all at once. Just update it for the user who logs in.
At the end, it will be updated for every user I think.
yes this possible with Cron Job 1st Create your php file with your condition use update query then add this cron job file in your server Cron Job Section and select date when you want to run this file. in cron job just file your cronjobfile.php name , Date and time when this file run.
Short answer: Use Cron job.
Syntax and usage of how to use it is almost straight forward. Here's a cheat sheet.
Note: If you're on a shared host, some hosts don't allow you to use cron job.
Edit: What #Havenard suggested is correct. The below cron job will visit the url once at minute 00 of every hour:
0 * * * * wget http://www.mywebsite.com/some/link
Related
I'm building a market place with auctions. I need to end auctions preferably at the exact second they are defined to end according to their record in the mysql database.
I know about CRON jobs and I'm currently running a CRON job every minute to execute some script which checks if there are sales that should end.
However this sometimes means that an auction ends almost a minute too late, which is not acceptable. Does anybody know how to make this more accurate without putting a lot of load on the server? For example I wouldn't want to run a script every second to check if sales have ended.
Check timestamp everytime a user try to click auctions button. So even the page haven't refresh and times up, user is not able to bid your item.
Is it possible to run a script after few hours or at specific time automatically with Laravel even if the browser window is closed?
I am trying to build a web based system where employee checks in when they arrive at office and the office time ends at 6:00PM at evening. So if the user do not checks out manually, the system should run a script automatically and checks the user out at 6PM.
Also there is option for employee to take a break for 20 max minutes, so if the user does not end the break after 20 mins, the system run a script to check the user out.
You can set a cron job for your script.
I want to check the stock level every day at a certain time (say 11pm GMT) and email a list of items that are low on stock to the admin. I have managed to get the mailing function working but I am struggling to limit the checks to once a day (right now it sends an email to the admin email every time the page loads)
Your help will be much appreciated!
I think that you just need to put your script in a separate file and run once per day with a cron job
You might want to read more about cron jobs in this post How to create cron job using PHP?
In case that impossible to run a cron job, you can save last mail time in DB or file and check timeout on page load.
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.
I hope to limit the number of messages sent for users of my site develloped in sf 1.4, so the idea is to count for every user the number of messages sent for every day,so if a user exceed 10 messages for example then he can't send another message for this day he must wait until tomorrow.
I'm thinking to create a task and run it every day at midnight and put all number of messages for every user to 0, so my questions are :
Do you think it's a good idea to realize it?
Can someone now how to do to run a task or a code every 24 hours in symfony?
edit
Ok I have a cpanl on my server give me any tutorials to setup a cron job or sample code of Task,I don't have any idea?
A cron Job would solve the problem.
The cron jobs helps you to run codes automaticallly on the server, go through the link