Php update record, repeat region cron job [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
This has been a problem for me for a while, but I honestly have NO clue how to write this script. Essentially, what I want to do is have a cron job that will be called daily and then update all variables under the "Age" field in my database. I also have a date of birth while helps change this variable at the moment, (Subtracting todays age with the DOB). Ive looked up a lot for cron jobs and I understand that you have one file which has all the code in it to do one job.
What I THINK I should do is create a repeat region that just updates every record as it is pulled from the server, but other people have been telling me differently. I'm new in programming and this Cron Job thing has REALLY been confusing me on what I'm doing. If I could have a good explanation, or even someone help me write this it would be greatly appreciated.

Cron is just timesheet for periodical jobs. So you should write your script with code wich will update needed data. For example this script will be updater.php. Then you should add to crontab string like this (this script will be repeating every day in 12 p.m.)
0 0 * * * /usr/bin/php path/to/updater.php &> /dev/null
If you need help for writing updater.php you should add some info about your schema

Related

Cron job for Laravel json api [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I will try to explain what I am trying to achieve. I am writing laravel json api with MySQL. Imagine user creates record inside my database. What I want to do is perform some kind of operation 24 hours after this record is created. It's something like cron job but what will be the the best solution? Should I run cron for example every 5 minutes and check if expired 24 hours for any of the records? Or maybe there is better solution?
You should use the Laravel queue system for this. When you insert a record in the database, you should create a new delayed job. Set the delay to 24 hours and Laravel will execute the job at that moment.
AfterInsertJob::dispatch()->delay(now()->addHours(24));
cron is fine, but (mysql) databases have events, which can be scheduled. In my opinion, this is really down to your personal taste and therefore more or less off-topic here. I mean an update after 24 hours on the entries is one SQL statement which should be rather fast, unless you have millions of entries ;)

Send auto email on delay for each MySQL entry [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I currently have a MySQL database that sends an auto email each time a new record is entered. I need to also send a reminder email to the email address in each row 5 days after it is inserted. What is the best way to do this? Can I use a MySQL trigger or a cron job? I will likely need step by step instructions, if it isn't through PHP. I've done quite a bit of searching but can't find exactly what I'm looking for.
A cron job is what you need. The php file doing the cron needs to query the table for rows where the entry date is equal to 5 days ago. The mysql query is:
SELECT `email` FROM `entries` WHERE date(`entrytimestamp`) = date_sub(curdate(), INVERVAL 5 DAY);
Hopefully this gets you started in the right direction. You'll need to make sure that the php file cannot be called outside of cron, that cron only happens once a day, or maybe keep a separate table logging the emails where you would add a "NOT IN email_log" condition to make sure that you don't double up on emails to someone.

Insert data into table automatic after 2days [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I created table account here 5 columns a/c_no date, deposit withdraw balance. I need to insert data automatic after 2 days with date and value of interest. How to code this?
For this you have make a scheduler kind of thing, that runs on scheduled time and do the assigned task with the specified logic. In linux, cron is there for this purpose.
Cron Jobs are used for scheduling tasks to run on the server. They're
most commonly used for automating system maintenance or
administration. However, they are also relevant to web application
development. There are many situations when a web application may need
certain tasks to run periodically. Today we are going to explore the
fundamentals of Cron Jobs.
Reference

How can I time something in PHP? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to do on a script I`m working on that every month a part of the site resets.
Or a better example, Something like a Subscription, when you want to buy something and you need to renew it every month. How can I know its been a month?
In PHP you can't do regular cron jobs, and I will discourage you seriously from doing it with real cron jobs if you don't know what you're doing.
You can only register when you last executed that event and then check if it's been a month since then. This is a really simple sample cron:
<?php
$lastexecution = /*logic to know when you last executed.*/;
/* It's either a database or a file or something similar.
* I usually use a database table that contains the records when I
* last executed a cron
*/
if (time() > $lastexecution + (30 * 24 * 3600)) {
/*CRON LOGIC*/
}
You also should look into flock() or some similar locking mechanism to prevent the cron being triggered by two different users simultaneously.
Note: In your case, with a subscription, you could add a expires field to your database that would contain the date and time when the user's subscription needs to be renewed. If that date is in the past, you tell them

Background update in database using php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
We have a database table with created datetime and status flag. We would like to update the status flag to the next status if the created date time has elapsed by 30 minutes without any user intervention. How can we achieve this in php.
Create a php file that does this status change in the database and program to execute it every 30 minutes with cron (Linux) or Task Scheduler (Windows).
You have to think carefully about how you design and use your database. Sometimes things are made overly complicated when they don't need to. For instance, in this case you could use a 'datetime' in your table indicating the start time. Any PHP script can now check whether or not the start time started 30 minutes ago, only when this information is actually needed. No need for a flag, cron jobs, etc.

Categories