Assign people an award after 7 days, Cron? Commands? - php

I'm making a website which awards people with a badge 7 days after they registered.
The application will send them a mail. Now i'm wondering
How can i do this without them having activity on the site? I can make it work that when they login i check the time that has passed since their registration. But i want to do it automatically
Should i do this with CRON?
Since i'm using laravel i've seen that laravel has Commands
http://laravel.com/docs/4.2/commands#building-a-command
Is that also a possibility?
thanks!

A popular package for this kind of job is Dispatcher which uses Laravel commands but with the power of a cron job. What I would personally do is create a dispatcher command that runs daily, gets the accounts created 7 days ago and then award the badges in batch.

Make a cron job run everyday and check the users for 7 days and award them a badge accordingly.

Cron is probably your best friend for these type of tasks.
If you're just getting started or if your project is of small-scale, cron will fit the job perfectly.
Otherwise, if you're looking into a more scalable solution, a queue and a scheduler would better fit those situations.

Yes cron is the best option for this.
You can setup the cron execution on your server, which will automatically hit the url after the defined time. Cron setup is also available through cpanel.

Related

what i need to do to convert my current system which use cron to use RabbitMQ?

my current script using CRON to handle the checking to DB and do the requests
so every mint the CRON will be called and check which action should be done as per the schedule table entry so if now the time to send email/publish post etc...
and this entry getting more and more with time and with many users now my CRON take around 20 to 50 mint to be done
so if I have to send email on 10 AM it sends between 10:20 AM to 10:50 AM
after searching I found RabbitMQ and Redis and other systems and I choose RabbitMQ
so what is next, what I need to do next, as for my experience I never work with a system like Redis etc.. so its something totally new, so if someone has and resources to check read or watch and help me with migrating the whole system from CRON to RabbitMQ.
small note, the current script is built on top of custom PHP framework only for this script and don't have API.
Write a php shell script for create linux pid in a infinite loop and call a method by cron.
Every job push to rabbitMq basic_publish with data set.
this method create a basic_consume with rabbitMq for performing queue with queue data set.

Run Special Tasks According To User Defined Times

I'm surprised I haven't been able to find something on this here - so if I've just completely missed it, please direct me to the proper thread.
Before I dive into any code, I'm trying to gather some good ideas for handling this situation.
We're developing a website with a list of tasks the user can select for the server to execute on their behalf. Automated emails, text messages, calendar reminders, etc.
I first went down the road of thinking about using cron, but as that the times and tasks for each user will likely change every day throughout each day - for this to be feasibly salable, I figured involving cron directly for each task could get pretty messy and buggy.
My next thought was to run a cron script every night at midnight and generate a task-list for the next day - but I'd still need cron or some sort of cron-like timing daemon to check the list against the time every minute.
I've run through several ideas, but they all seem fairly active or processor heavy. I'd like to find a good light-weight solution that can handle up to several thousand user defined tasks per day.
I'm working with your basic LAMP7 stack. If anybody has dealt with a similar task, I'm just looking for some good ideas to consider.
Thanks in advance.
You can use ReactPHP application run in background in your machine.
Then you can create a simple http server on your ReactPHP application for recieving the user data from your webserver such as you specified LAMP7. And once you recieved that you can trigger those events by setting asyncronous timer on the event-loop.

PHP-send an email at specific time

My system is for reservations, and I want to send a reminder email 15 minutes before without using cron on Linux/Unix/BSD boxen nor Scheduled Tasks on Windows because I'm using mac and the users' PCs will be windows.
So, what should I do?
Initially, I compared all date and time with the ones in the data base but still nothing arrived.
Thanks in advance.
I tried if the date&time now = the date&time in the DB send a conformation email.
and about the corn I have 2 things:
1- I'm using mac -as a programmer- and if I want to implement this function I'll have to use Scheduled Tasks on Windows which - as I think- will be need working on a windows environment.
and the system will be installed on a Microsoft PC.
2- I have not dealt with corns before, and I'm afraid it'll take time that I don't have.
You have to use some kind of service or job to trigger the email to be send. Because php is self needs to know when to exec the code ("script").
Use CRON or Task Scheduler or build your own job / Service
For Scheduling jobs on linux you can you at command. Here is example
at 12:32 -m -f /usr/local/bin/backup-script
Here is good manual for at linux.
http://www.brunolinux.com/02-The_Terminal/The_at_Command.html
If you want to avoid cron job, then you have to depend on some hacky solution to trigger/call your "send email" code
like,
depend on site users. If they are coming on regular intervals every minute, check on each reservation the upcoming reservation time and email to them.
run a daemon process OR a function that keeps running for a specific period of time, say 24 hours, and check for upcoming reservations every minute or xyz time. You can put this process on sleep for a minute (or more) to check reservations on regular intervals.
use 3rd party cronjob scripts or hosted cronjobs. like https://www.setcronjob.com/ (needs $ for this solution) or onlinecrontab.com

Pushing updates on exact scheduled time

I am creating a scheduler using PHP/MySQL where I have to allow the use to select date and time for publishing the content. The requirement is, the content should get posted at the exact scheduled time. If I create cron job, the notifications won't go out at exact time.
Running a cron job every minute is not really feasible in my case since I have to publish using an API and that itself is time consuming.
Is there any other way I can implement to make sure that the exact time provided in scheduler is followed. One of the best example that does this is Google Calendar which sends the reminders at the time you ask for.
Aditya
You should consider creating a daemon. The PEAR System_Daemon would be a great starting point. The daemon should essentially be a loop that queries the database, posts the content if necessary and sleeps.
Some sections of their documentation you might be interested in:
What is Daemon
Daemons vs Cronjobs
Installation
Example
YOU SHOULD CREATE CRONE JOB TO ACCOMPLISH THIS.

cron jobs or PHP scheduler

I am using MYSQL as my database and PHP as my programming language.I wanted to run a cron job which would run until the current system date matches the "deadline(date)" column in my database table called "PROJECT".Once the dates are same an update query has to run which would change the status(field of project table) from "open" to "close".
I am not really sure if cron jobs are the best way or I could use triggers or may be something else.Also I am using Apache as my web server and my OS is windows vista.
Also which is the best way to do it? PHP scheduler or cron jobs or any other method? can anybody enlighten me?
I think your concept needs to change.
PHP cannot schedule a job, neither can MySQL. Triggers in MySQL execute when a mysql query occurs, not at a specific time. Neither
This limitation usually isn't a problem in web development. The reason is because your PHP application should control all data going in and out. Usually, this means just the HTML that displays that data, or other formats to users, or other programs.
In your case you can think about it this way. The deadline is a set date. You can treat it as data, and save it to your database. When the deadline occurs is not important, it is that the data you have sent in your database is viewed correctly.
When a request is made to your application, check if the date of the deadline is in the past, if it is, then display that the project is closed - or update that the project is closed, just before display.
There really is no reason to update data independantly of your PHP application.
Usually, the only things you want to schedule are jobs that would affect your application in terms of load, or that need to be done only once, or where concurrency or time is an issue.
In your case none of those apply.
PS: I haven't tried PHPscheduler but I can guess it isn't a true scheduler. Cron is a deamon that sleeps until a given task is due in its queue, executes the task, then sleeps till the next one is due (at least thats what it does in the current algorithm). PHP cannot do that without the sockets and fork extensions, as special setup. So PHPscheduler is most likely just checking if a date for a task has expired, on each load of a webpage (whenever PHP executes a page). This is no different then you just checking if the date on the project has expired, without the overhead of PHPScheduler.
I would always go for a cron job for anything scheduling related.
The big bonus point is that you can echo info out as well and it get's emailed to you.
You'll find once you start using cronjobs, it's hard to stop.
cron does not exist, per se, in vista, but what does exist is the standard windows scheduling manager which you can run with a command line like "php -q -f myfile.php" which will execute the php file at the given time.
you can also use a port of the cron program, there are many out there.
if it is not critical to the second, any windows scheduling application will do, just be sure to have you PHP bin path in your PATH variable for simplicity.
For Windows CRON jobs I cannot recommend PyCron enough.
While CRON and Windows Scheduled Tasks are the tried and true ways of scheduling jobs/tasks to run on a regular basis, there are use cases where having a different scheduled task in CRON/Windows can become tedious. Namely when you want to let users schedule things to run, or for instances where you prefer simplicity/maintainability/portability/etc or all of the above.
In cases where I prefer to not use CRON/Windows for scheduled tasks, I build into the application a task scheduling system. This still requires 1 CRON job or Windows Task to be scheduled. The idea is to store Job details in the database (job name, job properties, last run time, run interval, anything else that is important for your implementation). You then schedule a "Master" job in CRON or Windows which handles running all of your other jobs for you. You'll need this master job to run at least as often as your shortest interval; if you want to be able to schedule jobs that run every minute the master job needs to run every minute.
You can then launch each scheduled job in the background from PHP with minimal effort (if you want). In memory constrained systems you can monitor memory usage or keep track of the PIDs (various methods) and limit to N jobs running at a given time.
I've had a great deal of success with this method, YMMV however based on your needs and your implementation.
how about PHPscheduler..R they not better than cronjobs? I think crons would be independent of the application hence would be difficult if one has to change the host..i am not really sure though..It would be great if anyone can comment on this!! Thanks!

Categories