run a task or code automatically every day - php

I hope to limit the number of messages sent for users of my site develloped in sf 1.4, so the idea is to count for every user the number of messages sent for every day,so if a user exceed 10 messages for example then he can't send another message for this day he must wait until tomorrow.
I'm thinking to create a task and run it every day at midnight and put all number of messages for every user to 0, so my questions are :
Do you think it's a good idea to realize it?
Can someone now how to do to run a task or a code every 24 hours in symfony?
edit
Ok I have a cpanl on my server give me any tutorials to setup a cron job or sample code of Task,I don't have any idea?

A cron Job would solve the problem.

The cron jobs helps you to run codes automaticallly on the server, go through the link

Related

How to run a PHP script automatically in every month

I have the php project for user can register and buy the hours to listen music or video, the not used of 50% hours have to rollover to next month, I wanted to automate this process when user complete one month I have to check their usage and process the rollover using php. I have following user details on DB, Signed-up date with time and usage and hours they purchased and used hours. I want to do it once in a month for each customer.
Is it possible using cron jobs? I don't have any idea to do this.
Not sure if this is the right approach but I've been running such kind of scripts when a user logs into his account.
For example.
You can do something like on successful login request by the user
if(date of buying hours has crossed the specified limit) /here you can check for expiry date/
{ // run your script here
}
else{}
just a suggestion!
You don't need to update all of the records all at once. Just update it for the user who logs in.
At the end, it will be updated for every user I think.
yes this possible with Cron Job 1st Create your php file with your condition use update query then add this cron job file in your server Cron Job Section and select date when you want to run this file. in cron job just file your cronjobfile.php name , Date and time when this file run.
Short answer: Use Cron job.
Syntax and usage of how to use it is almost straight forward. Here's a cheat sheet.
Note: If you're on a shared host, some hosts don't allow you to use cron job.
Edit: What #Havenard suggested is correct. The below cron job will visit the url once at minute 00 of every hour:
0 * * * * wget http://www.mywebsite.com/some/link

PHP triggering mail functions at a set time and date

I want to check the stock level every day at a certain time (say 11pm GMT) and email a list of items that are low on stock to the admin. I have managed to get the mailing function working but I am struggling to limit the checks to once a day (right now it sends an email to the admin email every time the page loads)
Your help will be much appreciated!
I think that you just need to put your script in a separate file and run once per day with a cron job
You might want to read more about cron jobs in this post How to create cron job using PHP?
In case that impossible to run a cron job, you can save last mail time in DB or file and check timeout on page load.

How to display timer for cron job

I am currently working on a site that sumbit data from one table in the database to another table in the same database every 12th hour. I would like to display a timer that shows when the specific cron job is scheduled to run.
Maybe if this could be done in jquery to set up an automatic timer?
I hope someone know what to do to display this.
to do so You can do it by 2 ways as i know and there is the easy way and the hard way
1. the easy way
set the timer on your cron job and you can set same timer on a jquery clock there is a lot of them if you are using Chrome you can find them here on Chrome Store
Count Down Timer
2.The Hard way
is to access the Cpanel API and write your own Code to get the time
Cpanel API
That's what i came up with

Schedule alarm notification system php

I need some help regarding the implementation of the following alarm.. Here's the flow of the program, user login to the system and then they can click the hyperlink create schedule and then from there they can create schedules using the form. After which, user can choose to start this schedules that they created and they can allocate a timeframe to it. For eg, if the user assign the schedule to run at 2pm the system will have a pop up to notify and inform the user to run this schedule probably 15 mins before 2pm..
I would like to know what are the ways to implement this in php and if possible is there any reference i can use on the website? I've tried to find but apparently most scripts are paid etc.
I think you are looking for scheduler kind of thing, to do this in php
you can use scheduler for windows os
cron job for *nix based os
Yes the answer to this question is pretty much related to CRON job. Take a look at this answer
Execute Query on a Specific Date and Time
You need to write a PHP script that scans the db and sees for the user who should be notified (i.e their deadline has arrived). Run this script in the scheduler (maybe every 1 hour) and it will do the magic for you. Good luck with your notifications :)
No cron job is needed if you only notify user with popup on the web site, however, you will need a cronjob if you want to send emails.
You will have to store users schedules (possibly in a db table)
When the user logs in php should check if there's a task due in the schedules table for that user: if yes show the pop up.
You will need to create an ajax call (with users id) that will call a certain php (say ajax.php) file every minute. You can help yourself with jquery.
The ajax.php should check if there was a task due in the past. If yes it returns job details (as json or html, you chose) else it just returns that there are no jobs.
When the calling ajax code recieves an answer from ajax.php, it does nothing if the answer is that there are no jobs or displays a popup with job details recieved from ajax.php.
The user can dismiss the call (delete it from the schedules db table) snooze or reschedule it (update the due date in the schedules db table).
Don't forget about security especially in the ajax.php: it has to check if the user is logged in.
Only if you want to prompt non logged in users by email you will need to set up a cron jobs, that will ping the ajax.php file periodically.

In PHP, how to keep a process running to monitor for an event?

I have a DBMS assignment to create an entire online bidding website that allows users to do many things like bidding on a timed auction, buy-it-now based on timed availability, and search among MANY more things. I've completed the website, with one minor exception: once a user wins a timed auction, that user must be notified that s/he is the winner and given 24hrs to checkout the item.
My early approaches consisted of simple PHP scripts that queried the DB when the user was on the page to see if the bid time ended and to see who the winner is, but there are two things wrong with that approach. 1. The user has to constantly refresh to find out if s/he won -- if they're on the page shopping. 2. If the user doesn't log into the site for a month after the auction ended, s/he will not know for a month that s/he won the auction and therefore misses the 24 hr window to checkout.
I've been reading about cron jobs, but my concern is that, since they are scheduled jobs, there are no convenient times to schedule the jobs so that they get processed efficiently. What I mean is that I can't continuously monitor and let every user who wins know instantly after the auction ends.
I also read on PHP exec( ), but I'm not sure that it's the tool that I need to run this task because once exec( ) finishes, it doesn't re-run.
So I guess, my question is if anyone has an idea of what I could implement to help me with this task.
You should use cron - have it run every minute or so to check the DB to see if some auction ended. The greater problem I think you're construing is the notification to the user. If its the case they may not be on the site (or on some random page when they win) then don't rely on notifying them via the website and certainly not from a PHP request they may or may not make to the site. Instead, consider having the PHP called by cron to check for winners send an email to them to notify them.
Think about Facebook (only because given the user base its the most universally experience example) - they provide a notification area if you're on the site, but if you're not on for a while, they send you an email letting you know something has happened. This is what you should do.
You should reconsider using cron scheduling, you can run jobs at very fast intervals.

Categories