I have been having some trouble finding a way to add a Laravel listener to a database. Basically, I have a database full of posts, and if a user hasn't updated a for 3 months, I want to send them an email reminding them to do it.
I have looked at laravel events, which may work. I also had the idea of running a continuous loop that checks if a timestamp has passed the 3 months mark, but that seems inefficient. What would be the best way to implement this feature?
Just run a cron task once a day to look for users that have not posted in over 3 months. There's no need to be any fancier than that, no?
Related
I've been looking through Laravel's queue and schedulers and I'm not sure if it's what I need to do what I want. I'll try explain simply.
First, I hit a submit (basic form) that creates a db row with say a number and a created_at and finished_at. JS then creates a timer on the page that counts down (math) from the created at to the finished time.
I can do all that fine, what I'm struggling to get my head around is how do I make this then change that number value of 0 to 1 say after 10 minutes, or whatever time I wanted to specify? I'm not sure how to go about this. This sort of stuff is new to me.
Any help/pointing me in the right direction would be great! Explanations too. :)
Edit: To add, I looked at things like socket.io but I'm not sure if that's what I want too and if I can even use that with laravel as it's a framework off of node.js
Is the backend actually doing any work besides storage? If not I would skip the complexity of trying to open a web socket to tell the frontend the task is finished.
If all you're trying to accomplish is display something on the frontend to the user after an interval of time I would just use JS 100%.
However if the backend does need to do work and trigger the display change on the frontend you will need to open up a web socket.
Your constraint on Laravel's scheduling is that they are run at predefined times. So if these actions are triggered by the user and not a set time, skip using the scheduler. Instead use Events to broadcast something to node.
I'm developping an admin panel with ExtJS.
I've almost finished it except one thing: I need the "partner" who logs in to be able to configure when he/she works.
I'm like re-inventing the wheel, but thanks to ExtJS and my structure this won't be a problem.
The actual problem is about UI design:
I want to make very simple so that it's possible to enter very simple values like "I'm working each working days from 8 to 12 then 14 to 18"
I want to make it more configurable and be able to precise "I'm on vacation from july,1st until august,31th"
I want to make it even more configurable and be able to precise "the month of january, I'm working every single day from 8 to 20 non-stop".
I was looking for some inspiration with Microsoft Scheduler but to be honest, a basic user will never ever (ever x 87) be able to use such a UI to configure when he/she works
Same for unix cronjob. From my point of view, this is very hard to understand from a basic user's point of view.
So my question is: do you know where I could find some inspiration for this? And maybe if there are some Php components well written out there to handle such things...
Here's the way I did it: a "list" of rows that contains:
start hour
end hour
start date
end date
and a list of associated days.
This way it's possible to configure any kind of scenarii, even though it requires a bit of thinking, because you do not have to enter it a "natural" way (= you usually think first days of week you work, the hours and maybe the start/end days = it's the opposite of my configuration).
I'm implementing an application that would check if the time is 4 or 6 or 12 hours after the data was inserted in the database.
So for example:
The data was inserted 1pm, then it's already 5pm (so this is 4 hours after the data was inserted), my application would process another task (no need for an explanation for this, I got it cover :D )
So this is a picture of my database fields:
id | name | time_added | time_to_check
ID is of course a type INT()
name is Varchar()
time_added is a type INT() because I am using time() function of PHP to insert a value.
time_to_check is a type INT because this is the field where i'll insert the 4,6, or 12
So my question is how would I implement this one? Is setting up a Cron Job a good idea to perform this task?
If Yes, every what time should I run the Cron Job (every 15mins,1Hour, Once a day)? I know there are lots of consideration in doing this task. So I need your ideas guys.
If you have an idea please share it to me or even code how you think to implement this one, it would be a great help!
Thank you very much! :)
ADDITIONAL INFO:
My concern about running it every minute is that not all of the data are inserted at the same time. Like for example: Data1 was added 3:15pm and time to check is 4 hours
Data2 was added 3:20pm and time to check is 4hours. What if the cron job didn't execute during 3:15pm or 3:20pm, what should I do?
If you need data to be routinely processed at 4, 6 or 12 hours after insert, you could also look at the Linux (not PHP!) 'at' command which allows you to queue processes to execute at a particular time. If you are expecting a lot of inserts then cron remains a better option though.
Cron is probably your best bet, having it check the database for records to check and going through them.
As for how often you want it, it mostly depends on how accurate you need the time to be. For instance, in my game I have a cron running every minute to check for fleets arriving at their destinations, but only every hour for checking if any banned users have served their sentence and need unbanning.
Yes a cron job would be good for this task. You would need to run it in an LCM of the times you'd like to check it. So from what I can see you should run it after 2 hours. (There would be a slight margin of error though - due to rounding). If you need complete accuracy you should check it every minute
I would recommend todo this task with a cronjob. The usage and some examples are explained here: http://en.wikipedia.org/wiki/Cron
The timeframe depends on your needs. If you check for 4,6 or 12 hours a cronjob per hour seems to be ok.
I have an idea for a project that I am currently working on, I am however struggling to find a way to implement this in PHP/MySQL.
I have a database with a list of activities that a tattoo parlour has, basically he works from 9 to 5 and when an event is added it is added to the database using date and time
| --- DATE----- | TIME |
2012-11-02 ---| 10:00:00
What I am trying to do is list all the times and dates within the tattooist timetable in the following week that does not already have events going on, this will also ensure the tattooist doesn't double book too!
any assistance will help guys, any assistance will help
The best way to create the application is to store each scheduled event into a database and "black out" dates that are already taken by the applications "events" table (per say)... You will probably want to do your event creation checks during the point that the event would be created or written to the mysql db.... You will probably want to have an events table with a start and end time for each event.... when you go to schedule an event (assuming user input dictates event time and date) just write a mysql query that selects the event where the DATE(a.lastevent) = DATE(NOW())... let me know if you have further questions
Edit:
I would build the front end of the application calendar style using a JavaScript interface. In the long run it will be much more user friendly and much easier to create, I've implemented them in a day.
The framework I suggest using is ExtJS, there are many tutorials and extensions for calendars, I know that ExtJS 3 has a calendar built into it and you can view a tutorial on that here: http://www.sencha.com/learn/using-calendar
Additionally, if you decide to use ExtJS4, you can use this plugin: https://github.com/bmoeskau/Extensible/downloads or this one http://www.sencha.com/forum/showthread.php?142488-Extjs-4-based-open-source-Calendar-application
The second link is open source, the demo looks to be Spanish (it does what you need and more), but if you use Chrome you'll get a bar at the top asking if you want the page translated, click yes, it does a great job. From there you can do find and replaces to get it to English.
The ExtJS 3 tutorial will show you how to interface the calendar with a PHP page so that you can update your MySQL database via AJAX. It is much simpler than you might think, and you'll save a ton of time trying to code it from scratch.
Sometimes it depends on how long each scheduled event might be. Are you adding these events with just a timestamp or are you also tracking how long of a block is being assigned?
you could have an appointment set using a start and stop time and some math..
I have a annoying tendency to use a epoch timestamp instead of a mysql date time. then you can make calculations to see if an appointment overlaps or find the gaps. just have to learn to count in seconds or provide math to adjust :).
I started making a MMORPG to improve my web design skills. I managed to make users able to move around the screen and get some items with a combination of Javascript, PHP and MySQL.
I want to show all logged users at the same time moving around and push info to the user on what the others I doing but I have no idea how to do it. What are the general ideas/methods to do this?
Thanks
Try using this engine to accomplish what you want: MMO.js... it allows you to build real-time MMORPGs in JavaScript using websockets =)
You basically create a table called "online" with two columns "ID,Time" and whenever a player does some action it updates "Time" that's for the logging part.
And you get a cron job to check the database and if the Time in the database is greater than the current time minus (for example) -5 minutes (timing out time) DELETE the row.