I've been searching for a while and think I have part of the information I need but just need some assistance putting it all together.
What I'm trying to achieve is to call a URL (a codeigniter controller) on a regular basis e.g. every 5 minutes which will go through my database mail queue and send the mail using amazon SES.
So far I have successfully created the controller, model, DB and SES is working just fine. The controller sends 10 emails at a time and it all works fine when I manually hit the URL.
I'm not too familiar with cron jobs, but think this is where I need to head.
My application is set up on Elastic beanstalk on AWS.
I think that I need a folder called .ebextensions in my web root, with a file called something.config in it, where I can put some 'container commands'. I also think I will need to include 'leader_only: true' in there somewhere to avoid my replicated instances doing the same jobs.
When I don't understand is what should my container command be, considering controller is 'http://myapplication/process_mail' ? From examples I've seen I couldn't see how it determines the frequency, or even the code that 'calls' the URL.
In my controller, I previously had the following code to ensure it could only be called from the command line. Is this something I can keep and have or will the container command just hit the URL like any other user?
if (!$this->input->is_cli_request()) {
echo "Access Denied";
return;
}
Thanks in advance for any help at all. I think i just need help with what should go in the config file, but then again I may have gone down completely the wrong path altogether!
UPDATE:
So far I've got as far as this:
I believe i need to run the application from the commandline like this http://ellislab.com/codeigniter/user-guide/general/cli.html
so my command would be php index.php process_mail
So what I actually need is help with running this command evey 5 minutes. This is what I have so far:
container_commands:
send_mail:
command: php index.php process_mail
leader_only: true
But what I don't understand is how I get this to run every 5 minutes, rather than just when the instance is set up. Do I need to create a cron job file on instance creation, with the php command in it instead?
Update 2:
To anyone else with the same problem, i got this sorted in the end like this:
an ebextensions file that looks like this: (.ebextensions/mail_queue.config)
container_commands:
01_send_mail:
command: "cat .ebextensions/process_mail.txt > /etc/cron.d/process_mail && chmod 644 /etc/cron.d/process_mail"
leader_only: true
a file called process_mail.txt in the same folder that looks like this:
# The newline at the end of this file is extremely important. Cron won't run without it.
*/5 * * * * root /usr/bin/php /var/app/current/index.php process_mail > /dev/null
So, every 5 minutes it runs via the cmd line the codeigniter main index file, passing in the controller name.
thanks to this: https://stackoverflow.com/a/15233848/2604392
I would set up the cron job to talk to the url, then store result in a MySQL database. Then regular PHP or any other app can connect to MySQL and access the data. That's the suggested way to connect to Twitter since a few months, so you can find info on how to do this floowing search for Twitter connectivity.
Hope this helps
By the way, while writing an email generating PHP script, I noticed that I have to slow down the pace of email sending to avoid being flagged as spammer. I added a delay of 2 seconds between emails and it did the job. My database was only 2500 so no big deal (except taking care of changing the PHP_MAXEXECUTION time variable)...
Related
The app is not even big,but it takes over 5 seconds to reload some pages,i don't think that is normal eventhough I read that laravel is pretty slow,but this is unusable,I've installed debugbar and it is showing that booting takes over 3.5 seconds while loading of the app is over 2.5 seconds,I've been following a course and instructor's app loads instantly,can someone tell me what effects the booting and load time?
Since this is a general question without specific detail here's a general answer:
Your first step should be to install the Laravel debug bar (which you say you have) and then look at the query time or controller time and narrow down the culprit. Based on that, you can ask more pointed questions on StackOverflow with the details of the specific queries that are slow, or if it's a controller that's slow, you can post the contents of that controller file. From there we can make recommendations in terms of what changes you can make.
One other thing to try is on the same machine try out a vanilla Laravel app and see what the baseline load times are. Maybe there's nothing wrong with your app at all and instead it has something to do with whatever is serving it.
Alright,I think I've got it fixed,was using XDebug for PHP lectures for collage and that is why app was running so slowly,so I've disabled it.
If anyone else will have similar problem here is the solution,but be aware that this will disable your xDebug:
Open XAMMP -> Click on config button for Apache -> Open PHP (php.ini).
Inside of that file look for "[xDebug]" and comment out all the commands that enable it ( in front of commands put ";" and space (" ") ) . It should look like this:
; [xDebug]
; zend_extension = C:\xampp\php\ext\php_xdebug-2.9.8-7.2-vc15-x86_64.dll
; xdebug.remote_enable = 1
; xdebug.remote_autostart=on
And then restart the server
If you need xDebug,then check out this post - PHP on Windows with XAMPP running 100 times too slow
I'm trying to set up a CRON job for my laravel 4.2 app and am strugglng to get things to work.
I've created a command which works successfully from the command line. I first tried created a CRON task with my service provider but was unable to get this to work. I tried:
/usr/bin/php /var/www/vhosts/mydomin.co.uk/subdomains/golfmanager/httpdocs/artisan reminder:week
This does not appear to work
I then tried:
/usr/bin/lynx -dump /var/www/vhosts/mydomain.co.uk/subdomains/golfmanager/httpdocs/artisan reminder:week
That failed to work either. My understanding is Lynx is a browser? but I assume because all the traffic is re-routed this approach won't work for a Laravel app?
So I then installed the package [liebig/cron][1] with a view to getting that up and running. I created a cron task with an external provider 'cronservice' which appears to be triggering but I'm not getting the expected results from the task.
I have configured the package as described and have current placed the following in bootstratp/start.php
Event::listen('cron.collectJobs', function() {
Cron::add('reminder-week', '*/15 * * * *', function() {
echo "Running Task";
Artisan::call('reminder:week');
return true;
});
});
The package logs activity to a database. I can see a log entry suggesting it's fired but can't see an entry that the job has worked. Laravel log files suggest there is an httpfoundexception
I've not created a route for CRON - the readme suggests it's using an internal one?
I'm quite confused. I'd like to stick with the package approach and the external provider but not sure if I now need to create a route and how I can test the set up is correct and the jobs will work.
I've tried running the script from the browser `http://mydomain.com/cron.php?key=xxxxx' but that also throws an httpnotfound exception
ANy help appreciated to get this to work
I changed the Event::listen code to app/start/glopal.php and all working now.
Re-read the readme more carefully!
I have problems setting up a cron using CodeIgniter. I've followed the documentation and set up a test cron
* * * * * php /home/USERN/public_html/spider/index.php tools message
But this doesn't work. The output is just the index.php default controller, and not tools/message. When I run it in the terminal on the server, I get the results that I expect. Is there something I am doing wrong, or do I need to change something on the server?
For cPanel servers, in order to for CI to use the URI segments right, You'll have to use
/usr/local/bin/php
The problem i have is that i have created newsletter template, added few subscribers and i can add the template with subscribers into queue - all that works fine.
I can also run the cron.php from the browser - it runs without errors, but the damn e-mails are not going out anyway. For that reason i have not done the crontab -e and added the stuff into that file yet. As far as i see - it does not matter where you execute the file from - be it crontab, shell or browser - it should work in any case. And i can see that it is not working.
Any ideas?
Alan
May I suggest you take a look at the cron_schedule table of your database ?
As soon as the cron.php file has been called (should it be via crontab or via a browser request), there must be a line added to the table. The line is "newsletter_send_all".
If a previous "neswsletter_send_all" was scheduled it should be run and its status set to "success" and the new one to "pending". Or, if there's a problem, the warning message is stored in the cron_schedule table on the same line as the newsletter_send_all that failed.
If when running cron.php the cron_schedule table is not appended with a new line, there may be a problem with the config.xml file of the Newsletter module or with your cron settings in the admin configuration. About that last subject see : http://www.jnorton.co.uk/blog/setting-magento-cron-system
All the above may give you a few tracks.
Are any emails being sent from Magento? (such as order confirmations)? If not, you might need to setup your email sending options or the outgoing email settings on the server.
Navigate to Configuration>Admin>Security, select “No” in “Add Secret Key to URLs”, save configuration.
Src: http://www.magentocommerce.com/boards/viewthread/2424/P105/#
I have an MVC architecture and since I already have an action that would be extra useful if automatically called every hour or so, I wondered if there's a way to set it up as a cron job?
Don't know how periodic web page request is related to mvc, but you can achieve this by adding following line to crontab (1 hour period):
0 0/1 * * * wget <web_page_url>
Which is translated to: use wget command to request <web_page_url> every hour at zero minutes.
You can use
curl http://example.com
Or if the language you're using has a CLI client like PHP you could just run the script like
php /var/www/example.com/index.php
Edit:
For an MCV app it's probably easiest to use curl