I have the following code in Kernel.php. The purpose is to run the command between 23:000 and 04:00
$schedule->command('moving:vehicles -vvv')
->between('23:00', '04:00')
->everyTenMinutes();
However, the cron starts executing the command at 17H00. I have tried to replicate the same by send emails into mailtrap and I get different results.
https://github.com/laravel/framework/issues/28943
The link above explains why the schedule was not running as intended. It was a bug in Laravel 5.x and it was resolved in version 6. I changed direction to use https://crontab.guru/#*/10_0-4,23_*_* to solve the issue I faced.
Related
I have an "/x" api endpoint that dispatches a "MakeXJob" Job (without ShouldQueue). In local environment without Octane, it works just fine. But in Server with Octane (Swoole), does not dispatching the job. I am dispatching in command line with tinker (to see if there is a problem), and it works expected again.
Has anyone encountered such a problem before? This is the second Octane(!) related issue I faced. Of course I am not sure if they are "Octane" related, it's just an idea.
Here is other issue: Laravel Request Class prepareForValidation not reflected in $request->get()
Just upgraded from Laravel 6 to 7, and had the error response above when submitting a contact form. I eventually found a solution that seems to work and I am submitting here to help out the next guy.
In the terminal run:
composer require illuminate/mail
Add the following to the top of the controller file (app/Http/Controllers/Main.php in my case):
use \Illuminate\Support\Facades\Mail;
Add this to bootstrap/app.php:
$app->register(Illuminate\Mail\MailServiceProvider::class);
Save and test, and it worked localhost.
If the above does not work for you, there are some other possible issues and solutions available at this link, where I must give credit to vipindasks.
https://laracasts.com/discuss/channels/lumen/lumen-52-mail-not-working
Since I am suppose to ask a question:
Do you see any problems with this solution even though the site and mailer is working now?
You are simply missing a backslash. This tells the autoloader that the file you are looking for is not in the namespace your controller resides in :
$app->register(\Illuminate\Mail\MailServiceProvider::class);
Run composer update hope this will help you
I am haveing trouble with getting a cron job to work with codeigniter
I have used these instructions.
https://www.codeigniter.com/user_guide/general/cli.html
But it is not working
Here is what I have.
php /home4/markwolf/public_html/propalert.asia/index.php admin_notifications index
But it is not finding the right controller or the method, instead it is going to the "default_controler". Everything else I've tried gets a 404 not found error.
I've been pulling my hair out for two days trying to get this to work so any help would be greatly appreciated.
Thanks
EDIT
This works:
wget -q http://propalert.asia/admin_notifications
But the problem with this method is that Codeigniter's method for protecting the script by checking whether it is accessed by cli returns false.
I came across this post at CI's forum describing the same problem.
https://ellislab.com/forums/viewthread/236475/#1055830
Unfortunately he never got an answer there either.
I finally found the solution:
/usr/bin/php-cli -q /home4/markwolf/public_html/propalert.asia/index.php admin_notifications index
the key is "php-cli" instead of "php".
But then there is a bug in the CI core that needs to be fixed. You can find the solution to that here:
https://ellislab.com/forums/viewthread/227672/
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'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)...