Cron Job in Laravel [duplicate] - php

This question already has answers here:
Cron Job with Laravel 4
(4 answers)
Closed 7 years ago.
I am trying to develop a cron job for a command I have already created. I am completely new to cron jobs so I dont really know how it works.
Trying the command by myself in the console works perfectly. All I need is to be able to execute it every 24 hours. I am using Laravel 4, can anyone help?
Thanks!

To create a cron job as root, edit your cron file:
[sudo] crontab -e
Add a new line at the end, every line is a cron job:
25 10 * * * php /var/www/<siteName>/artisan <command:name> <parameters>
This will execute the same command at 10:25AM everyday.
Just make sure you keep a blank line after the last one. And you also might need to use the full path of your php client:
25 10 * * * /usr/local/bin/php /var/www/<siteName>/artisan <command:name> <parameters>

You could register your cron job like this:
php /path/to/your/laravel/project/artisan your-custom-command

See my answer on this question, my example is for L3 but should work for Laravel 4 accordingly.

Related

How to delete specific cron using php

I want to create and remove cronjobs using php. I am using
exec('echo -e "crontab -l\n30 9 29 7 * curl http://myurl/send-cron" | crontab -');
this code to create cron and right now it's working good but I also want to delete specific cron how can i do this and please tell me is this right way to create cron using php

Unable to run php script using cron [duplicate]

This question already has answers here:
Cannot get PHP cron script to run
(4 answers)
Closed 8 years ago.
I am running a php script using cron. The name of the file is : PriceChecker.php .
This is my cron script
# m h dom mon dow command
0 07,11,16,20 * * * php /var/www/mainsite/PriceChecker.php
* * * * * /var/www/mainsite/pricecheck.sh
The shell script is:
#!/bin/bash
php PriceChecker.php >logger.log
The first line is the original. The second is for testing
I have tried various variations including: /usr/bin/php /var/www/mainsite/PriceChecker.php
If I log the out in the cron php /var/www/mainsite/PriceChecker.php > logfile.log
The logfile is created, but is empty
Same as here, I think Cannot get PHP cron script to run
You forgot to specify the user name you want your script to be run as.
Specify the full path of the PHP file to be execute
Okay what worked was CDing into the directory of the script
https://serverfault.com/questions/97828/php-from-command-line-path-problems/97881#97881

Keep loading my script [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
schedule an email in php
How can I keep loading a PHP file on my server after every hour?
It will mail me something. Actually it mails me something when I visit it. But I want it to mail me after every hour. So someone should either visit it each hour or I have to use cron job like something.
Any help will be appreciated.
You should use a cronjob.
Start by opening you terminal and run
crontab -e
You may need to configure your crontab settings (default editor) if this is the first time you are using crontab. Now, in your editor, you have to call your php script like this: (it is set to be called each hour)
0 * * * * /path/to/php /path/to/your/script.php
You can also use an alias of hourly.
#hourly /path/to/php /path/to/your/script.php

Sending email with cron job?

hi i am working on send email every day 10am so i search lot of sites so i find using crone then it's possible to send email actually iam new to using crone so how can i install crone in my server please provide me some samples on sending email using php with crone.
Thanks for advance.
cron is probably already installed on your server. you will access it with:
crontab -e
To make it email with php you will probably want to use something like this: http://pear.php.net/package/Net_SMTP/
Cron is the inbuilt functionality provided by linux. it is a task scheduler. you need to set the cron to execute a php script every day at 10 am. this php script will contain the code for sending emails.
To see already set cron jobs use crontab -l to set new cron jobs use crontab -e. Your cron job looks as follows
1 2 3 4 5 /path/to/command arg1 arg2 OR 1 2 3 4 5 /root/backup.sh
Where,
1: Minute (0-59)
2: Hours (0-23)
3: Day (0-31)
4: Month (0-12 [12 == December])
5: Day of the week(0-7 [7 or 0 == sunday])
/path/to/command - Script or command name to schedule
Check this link for more details How to Cron jobs
Also you may need to set the path to php executable in your php script, something like
#!/path/to/php/executable
as cron is Linux command it need to know which program to use to execute the given script. the above line goes as a first line before opening php tags.
Setup the cronjob:
$>crontab -e # this command line command sets up the cronjob and opens the vi editor
Linux Crontab Format
MIN HOUR DOM MON DOW CMD
Vi editor opens: add your script there:
Example:
25 11 * * * .csh 2014_09_16 --> This will execute the csh script daily at 11:25am and send an email accordingly
Esc- Shift+zz to exit the editor by saving the changes
$>crontab -l # this cmd checks if the conjob is set
You can easily execute a PHP file using cronjobs, and let it take care of your email sending. I've written a tutorial here: http://rapliandras.hu/blog/how-to-execute-php-scripts-as-cronjobs/
If you are unsure of how exactly an email is sent using PHP, check out its mail function's documentation here: http://php.net/manual/en/function.mail.php

How can I set up cron job in my site using PHP?

I want to mail after 6 hours automatically to my user who hasn't fully completed form on my website.
Help Me
Use crontab -e to edit the cron table for your account.
In the crontab, put an entry something like...
0,10,20,30,40,50 * * * * /usr/bin/wget -O - -q http://path.to/cron.handler.php
or the equivalent
*/10 * * * * /usr/bin/wget -O - -q http://path.to/cron.handler.php
...which will run the cron handler php file every 10 minutes using wget (there are other options as well, and you may need to edit the command appropriately). (Note: you don't want to just run it every 6 hours, because then if someone happened to fill out the form right after it ran, it wouldn't have been 6 hours since they filled it out next time it runs, so you'd end up with 10-11 hour gaps.)
Then in your PHP file, find users who BOTH (a) haven't fully completed the form for at least 6 hours and (b) haven't been emailed yet. Send them an email, and mark them as having been emailed.
You will need to create the php script that does the checking and mailing, and then set the cron job like the following
/path/to/php -q /home/username/public_html/mycheckingscript.php
Obviously you will need to adjust the first path to point to your php binary, and the second path to point to the full location of your checking & mailing script.
I don't think you want to set the cron up using php. Instead write a php script and then have cron execute that script every hour or so. This would be something that is going to be dependent on your operating system.
For linux, here is the manpage for using crontab.
There is no way you can change/add a schedule on the cron job on the fly. according to my experience. because until now i did not find..

Categories