Automatically update data on website database triggered by date and time - php

I have a condition that I have to update data automatically on my website, which is triggered by time that I've set before.
EXAMPLE :
i've set the update for 29-05-2018 20.20 then the website will do update in that date and that time without any trigger, and no need to
open the website.

Create a Controller name Cron.php
than make a function run_every_day()
now put all your condition in this function than go to your cpanel search for a cron tab. Click on it create a cron task
give it the url root/index.php/cron/run_every_day
in the cron seeting set the time 1 day so it will run each day on specific time you set.
Hope this helps

Related

How to set values inside column to zero every 24 hour?

I have a website that let users download PDF files, I made a download limit 10 files per day for each user and I stored the numbers inside MySQL table under column named "downloads".
Each day I use this command to set all values to 0 for all users:
update users set downloads = 0
I contact my web-host provider and they refused to give me super user privilege to make schedule for this column to reset itself each 24 hour.
Is there any other way to make little code in PHP to reset that column from outside or any other way to do that?
Update: I can not run cron job either!
Save in the database the date and the downloads number in the same field, every time you update this field ask if the date inside is today if not save today's date and zero downloads for example your field will be:
date_downloadsTimes
03-02-2019_2
Store the last reset time in a file or the database and upon every new download request check if the last reset was 24h+ ago. If so, reset the download counter and update the time. That way you are not reliant on a background job.
Alternatively you could set up a route (some URL to be called) that is periodically called from an external source (either your pc or some web service), and resets your download counters.

How to execute some code on a specific datetime to the second?

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.

How to run a PHP script automatically in every month

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

Laravel automatically delete blog post when it pass its expiry date

In my Laravel app I upload blog posts. All posts have a unix expiry date eg 1492425121 What I want to do is to automatically delete all posts that pass its expiry date.
Right now I am running a cron job each night that checks for old posts then deletes them, but is there any other way I can delete them right away?
You can use scheduled task for that. In this task, do something like this:
Post::where('expiration_date', '<', Carbon::now())->delete();
Then instead of running your command on night make it schedule that it run every minute and check whether post exp time and server time equals then delete it ,
schedule your command like this way:
$schedule->command('MakeXpZero')->everyMinute();

PHP triggering mail functions at a set time and date

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.

Categories