I have a PHP web site. In this all my users have an expiry date about 1 month ( if a user register today his expiry date will be 2nd of the next year).I need to automatically update the expiration date of my user's profile and send a mail to that users( even he is logged or not). But I don't know how this? I heard about the clone function (I am not sure is it clone or not) to implement this type of automatic function. If does anyone know this please help me...
Instead of clone I think you mean cron. You can set up a cron to run a php script that will do these updates for you. Just write the php script that will do the update. Then, in your unix shell:
crontab -e
Specify the minute/hour/dom/moy/dow that the cron should run and then php /path/to/update/script.php
Related
I have one problem. I am learning cakephp 3 and I want to do the folowing:
User enters date and time (this is saved into mysql as datetime format) and system needs to send email few hours before this datetime that he enters (for example, 1 hour before)
However, I want to do this without cronjob.
So user enters 2019-05-12 12:00 and I want immediately to schedule task to send email on 2019-05-12 at 11:00.
Is this possible and yes, can you please give me any pointers? I also checked cakephp tasks, but it seems that I don’t see the whole picture yet
create Shell
bin/cake bake shell CronJobs
open created shell and create method to send email, for example:
public function sendEmal()
{
}
Inside this method add your code to select data and Mailer to send mail.
now in your cron tab set task and point to this shell script, example
* 1 * * * bin/cake CronJob sendEmail
Please read:
https://book.cakephp.org/3.0/en/console-and-shells/shells.html
https://book.cakephp.org/3.0/en/console-and-shells/cron-jobs.html
https://book.cakephp.org/3.0/en/core-libraries/email.html
Update:
However, I want to do this without cronjob.
Other way is to implement some Queue system.
Read here for more information
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
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
Id like to generate an automatic email at certain times of the week or daily from my website to certain users. i.e at 12am, or 5pm .I'd like an email reminder sent to user example#example.com. Can anyone point me in the right direction. I have read about cronjob but didn't got much information.
You are looking in the right direction... A cronjob would suffice.
This would allow you to run a php script on a schedule
Start by looking here
Do you have shell access to your host? Or does the host have CPanel installed?
If you have shell access, you can run the following command:
crontab -e
Then insert a new line like this:
* 0,17 * * * /path/to/php/executable /path/to/script/which/sends/emails.php
This will call your PHP script every day at hours 0 and 17 (12AM and 5 PM). The email sending should be done in /path/to/script/which/sends/emails.php
You need to create php script which will do all work (get data to send, get emails list, send data). After that You need to assign this script to schedule in crontab
I am currently working on a registration based website, and I have the server sending an activation email to the user upon registration. This is all done in PHP so, as you can imagine, I am using the mail() function.
This is all fine and dandy, once the user gets the email and clicks the activation link, the 'active' field that is in the 'Users' table is set to true. Here's the problem though, in the case that a user does not confirm their email address, what am I to do?
I have thought of holding details like the date and time the user registers but I don't know how to proceed with this data. How do I have the server automatically delete the user from the database after a set amount of time?
That's what I think I should be asking, but in all honesty I don't know the usual protocol...
Conclusion: Since Cron is for Unix based servers I've had to pass on it, but I found it very interesting that I could just use the Windows Task Scheduler that is built into Windows. This at least means I can test it on my PC before any server hosting. Thank you all
You should definitely store the date and time that the activation link was sent.
There isn't really a way to tell the server to automatically delete stale user data, but it's easy enough to code up yourself. Assuming you have access to cron on your server, you can set up a cronjob to run (for example) every night at 2am and execute a PHP script that searches the database for users who were sent a link more than X days ago but never confirmed it
i think the solution would be Storing the timestamp while sending the mail.
now run a cron every 15minutes which would check that which values are having timestamp more than 24hrs or any timelimit you want and then delete it from db
Just call in your index.php file the following code. (Why index.php ? - because it is requested every time and can "act" as a cronjob.)
(Just Pseudo Code - might need some tweaks!)
mysql_query("DELETE FROM user WHERE active = 'false' AND registerTime < (NOW-60*60*24*7)")
This will delete all Users which have not been activated within 7 Days.
It's just a concept idea i think you can build on.
You should look into cronjobs that you run daily. Simply put in a field in your database with the time your user registered.