Cron job for Laravel json api [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 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 ;)

Related

How to dynamically start and stop scheduled jobs at run time in Laravel? [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 4 years ago.
Improve this question
I have a case where the user wants to be able to add Jobs using the UI, and he should be able to start and stop them at any given time.
So the jobs should be added dynamically at the run time, how can I achieve this functionality with laravel?
You may want to check out the laravel-dynamic-scheduler package. Even if you don't use the package it still can serve as a nice code example for you.
You essentially create a proxy task, and then through that task, can dynamically call other tasks created by users. The proxy task can check a database table of tasks you can have user's manage.
It is essentially using the same method Laravel itself does in the scheduler, as the scheduler itself is really just a proxy for the system's Cron.

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

Limiting python script to run 15 times per hour in PHP [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 8 years ago.
Improve this question
I'm making a Twitter App and twitter makes it so any application won't run more than 15 times an hour.
I execute a python script when a user presses a button that gets the top 5 trends on twitter.
I am using PHP and MongoDB NoSQL to store my data.
When I searched for an answer I came across --> this but they are using a SQL DB.
My Question,
How can I tell the user has executed the script 15 times within an hour?
Each time the user runs the app, add their clicks to an object including its time.
When they run your script, pull these objects out, look through their dates, and delete everything with a timestamp more than an hour old and count the rest.

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