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.
Related
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.
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.
I am fairly certain this is an extremely easy thing to do for more of the experienced users, and probably shouldn't take more than a minute to do.
Unfortunately I have no experience with Cron Jobs, and despite reading documentation I can't seem to find any info on how to accomplish this.
I need to set up a Cron job to run every day at a certain time (This much I already know the syntax for), and what it needs to run is an "Export" link on my website that I use for product feeds.
The link is:
http://www.heroesofgc.com/index.php?route=feed/bidorbuystoreintegrator/export&t=73f6176e946fe85c5fb230b6040466d0
What command would I need to use to get it to work?
-I've read about using 'Wget', but I don't believe I have any such thing on my server at the moment (or don't know where to find its path at least).
Here shown, how you can set cronjob timing
http://www.adminschoice.com/crontab-quick-reference
http://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab
From what I can see Gearman does not support scheduled jobs or delayed jobs. I was thinking that perhaps the scheduled job could be queued in at first and then added to the Gearman queue after the at time period has expired.
at tasks are persistent as they are written as files to a directory in the spool directory of the server. So the only bottle neck would potentially be a simple script to add the task to the Gearman queue because at can't be distributed across servers. Passing it to Gearman to process the actual job means I can get proper job logging etc.
Is this the best way to approach this and do you have any alternative ideas?
The reason I have opted for Gearman over other queue solutions is that it has a PHP extension.
The code I am writing is used to maintain a queue of emails that need to be sent out. So I may specify that I want to send an email to example#example.org at 9.50 on Friday for example.
I have decided to go the at route as originally laid out in my question. For the purpose I have written a little PHP wrapper for the at binary and tested it on Ubuntu. If you are interested it can be found on github: http://github.com/treffynnon/PHP-at-Job-Queue-Wrapper
A rather hacky solution, which would only work well at hourly or daily resolution would be to make the job (function) name contain the date at which you wanted it sent. Then have workers starting in cron every hour or day to register for those jobs.
For example, if you wanted to send an email at 9AM on Monday March 12th 2012, add a job to the queue with a name like email_2012-03-12_09:00. Then have a cron job running hourly, which runs a worker who registers for any jobs matching email_ + current date and hour.
As I say, probably workable, but rather hacky!
UPDATE 1: I saw recently that the docs for gearmand database persistence now mention a field named when_to_run which is an INT, and could potentially hold a unix epoch timestamp. This field doesn't seem to be referenced in the code yet.
If you are using Zend...
SlmQueue is a job queue abstraction layer. It allows you to easily use job queue systems in a Zend Framework 2 application. Thereby it does not enforce you to specifically use one type of job queue. You can write your code and jobs independent of the underlying system. This enables great flexibility and decoupling of the systems.
https://github.com/juriansluiman/SlmQueue
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!