This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
email checking and then act upon script for reacting to a sms message
Suppose that I have two functions called recieve_email() and send_sms().
The problem is that I should send SMS as soon as a new email arrives.
As I have researched, there are these 2 solutions:
Checking emails using a cron job
Checking emails using a web page that is always open using javascript (like gmail)
I think that the more stable way is the cron job.
I want to know is that aceptable to run a cron job EVERY SINGLE MINUTE? Or does it kill the server and bounce my site away?!
What about running the cron job every two minutes?! :D
Question 2:
Is there an on_mail_recieved like solution? It will be of course faster and optimum.
I want to know is that aceptable to run a cron job EVERY SINGLE MINUTE? Or does it kill the server and bounce my site away?!
Generally, that's fine. If there's a chance the job will take longer than a minute you should generally implement a lock file or semaphore to prevent it from running multiple instances at the same time.
Is there an on_mail_recieved like solution? It will be of course faster and optimum.
Yes, you can pipe e-mails through to a script. This requires you to run a mail server and can be a little involved technically.
Related
This question already has answers here:
Send mails in background without cron
(3 answers)
send reminder emails with php and mysql WITHOUT cron-job?
(4 answers)
How to send dynamic content email without cron job
(2 answers)
Closed 5 years ago.
I want to write a php script that emails me on a specific date and time without anyone visiting the website or using cron.
I have a web hosting without cron and I'm wondering if it is possible to make a script for, for example a newsletter, to email someone automatically in the future?
Any help? Thx!!
Not unless you have a webpage that uses AJAX requests to mail you. But that would require leaving that web page up indefinitely. Unless I'm mistake, I'm unaware of any software to do this.
PHP can't email you without something provoking it (cron job or user visiting a webpage)
How should this happen? When there is no input to the server, how should the server know, that he has to do something?
This is exactly for which is cron: Periodically a script/program is started and this script can then do stuff (check the date, etc.).
Another trigger would be a visit to the site, where the script could check, if your date is reached and then do something.
One option left, a script which runs forever and checks periodically, if the time is reached. My guess is that this is not possible on your host, as the execution time is normally fixed to a maximum amount of time. (To prevent unintended loops and other things)
To conclude this: No, there is actually no way on a shared host, which do not allow cron jobs.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
schedule an email in php
I want to schedule my php script which sends emails using windows services as the website is hosted in windows machine. I am looking for a solution which does not involve cron jobs. I want users to schedule a time and the windows service should execute my php email script on the scheduled time so that emails are sent on the scheduled user time. I want to write the entire code in php.
You don't have access to cron jobs on a Windows Machine ;) But, there isn't a way to do that without the window's scheduler unless you have a VERY active site where someone is always on it, and then you can check and run on each page load or something similar. Otherwise, I would write a script that checks the DB for when emails are suppose to be sent - and pull the ones that are suppose to be ran that minute (or half-hour, or whatever intervals you allow your users to select from), and schedule run that script every minute/interval via the windows scheduler.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Best way to periodically execute a PHP script?
I need to run a php script which continuously collects information from one site, and as soon as that information is collected I need the server to store the information on the database and then update other sites and to continuously repeat the process. The only problem is that I need these php scripts to run without the user visiting the page or even the site for that matter.
Not only this I need the scripts to be running 24/7 or at least run when one site has changed, enabling it to update the others almost instantly. Can anyone suggest what I can do?
You could have your PHP script run as a cron job.
(Of course, you'll need to be able to set up cron jobs on your server)
You are looking for Cron Jobs: http://en.wikipedia.org/wiki/Cron
Many hosting providers have an interface that lets you set up jobs. If your provider uses CPanel, then see this page: https://documentation.cpanel.net/display/68Docs/Cron+Jobs
If on Windows, then use Scheduled Tasks.
You have to create daemon using PHP.
Have a look at this http://devlog.info/2010/03/07/creating-daemons-in-php/
I was wondering if there is a way to run a PHP loop in order to send a few hundred emails to subscribers in background. My goal is to format the newsletter, click send and then close the browser or change page. Of course, the actual process of sending the e-mail will be running in background and would not be interrupted by the browser closing.
I know this can be made with a cron job reading from a queue saved in MySQL or text file, but this way, even if there is no queue for a long period, the cron will always be running, looking for the queue...
I've seen this funcionality in a script called Pommo (https://github.com/soonick/poMMo) but can't seem to understand how it's done.
Does anyone have an idea for this?
I was going to add a comment to your question, but them I didn't have enough space there to format and give the example.
Here is an idea I believe might work:
1 - Load all the emails you want to send to a database or file.
2 - From your web application click on the button to send emails. This will submit an Ajax request to the server. You can define the number of emails you want to send within a certain timeframe. Remember that most hosts have limits on number of emails you can send every hour.
3 - create a php script that will receive the Ajax request and send all the emails within the parameters you define.
4 - I believe you can kill your web browser because the PHP script will run through the whole list and will not return until it finishes sending all the emails.
The above might work, however I would never do it this way. I would use a cronjob as stated above. Your cronjob would only have to check if there are emails to send or not. This is not resource intensive.
If you decide to implement the ideas above, please make sure you let us know. I am curious if that would work.
Good luck!
I know this can be made with a cron job reading from a queue saved in
MySQL or text file, but this way, even if there is no queue for a long
period, the cron will always be running, looking for the queue...
That pretty much beats the purpose of Cron. You should create a job that runs, say, every 15 minutes and checks the queue for mails that need to be sent. If there are no mails, let the script die, it'll run again in 15 minutes.
If there are mails to be sent, update the rows to indicate that you're processing them before you start sending, so a run taking more than 15 minutes won't cause another script instance to send the same mails.
You need a queue system. There is e.g. Beanstalkd for linux, which you would feed things with php.
I have a mailing script which loops through approx 900 subscribers (in database), building an individual email for each subscriber and sending via SMTP. This script is fired manually via the browser, however the number of records involved have resulted in the script starting to time out part way through. In tests, the error is almost always Fatal Error max execution time exceeded (although one time there was an error related to mail() and SMTP). I'm thinking that I should probably be running this type of script from the command line, however, the script still needs to be triggered manually (via a CMS admin user) - does anyone have any suggestions for a good way to handle this?
I think you can set the timeout for a PHP script from within the script.
However, I'd rather use CRON+PHP-CLI based solution. The PHP code remains the same whether you use CGI or CLI, however, in CLI mode there is no implicit time limit.
Tweeking the run time limit will only temporarily defer the problem.
You didn't say what OS this is running on - certainly if you've got a local MTA that may help, but the right solution would be to spawn a seperate process. Note that there are a number of pitfalls in this approach - see this post for details of how to do it correctly on Unix type systems.
set_time_limit (0); should do the trick.
There is not much to say about more efficient way, unless we see your code....
work with cronjobs and every time the cron executes the script it can send a small amount of mails.
For example the Typo3 mailer engine is invoked every 5 minutes and will check if any mails need to be sent.
So the user doesnt manually trigger the mailing script. The user only marks a newsletter which should be send by the mailer engine.