how to execute a php automatically on server - php

i am trying to run a PHP automatically on a server every 15 minutes. The PHP should send mails to some contacts from a database. I have created the PHP and tested it and it's ready.
Now i dont know how to set it to run every 15 minutes.
I read some article about it on this website and i saw something about cronjob. I know the server where i stored my php has the stuff installed to run cronjobs but to be honest i dont know where to start this. I have a ftp where i upload the phps and a froxlor admin panel.
I hope someone can enlighten me with this 'next level' thing :D
Thank you very much,
Daniel!

Type crontab -e, and add the below line:
*/15 * * * * /path/to/your/php/script
If you didn't add execute permission to your script, you need to add the php executive.
*/15 * * * * /path/to/php/executive /path/to/your/php/script

Search for "CronJobs" in the admin panel. There should be a section there for adding cron jobs using the interface.
When you create the cron job, you will see that there are various options to define the time interval when the task is repeated.

Just a small correction to what xdazz has to say:
*/15 * * * * php /path/to/your/php/script
You will need to prefix your script with "php".

add a cronjob
example cronjob code for php script(in directadmin):
php /home/username/domains/domainaddress/public_html/phpfile.php
example cronjob code for php script(in cpanel):
php /home/username/public_html/phpfile.php

Related

Cronjob is not working on Ubuntu 16.04

I would like to put in place some cronjobs for my website.
My actual cronjob is:
4 * * * * /usr/bin/php /var/www/domain/backup.php
But it doesn't work.
Mannually the cron job is working.
With a service like https://www.easycron.com it's working too.
In Terminal, when I make crontab -e, I see my cronjob but it does not seem to run.
From where I can start my search to understand ?
Thanks.
In my server, when setting up a php file to run, I only have to put:
4 * * * * php /var/www/domain/backup.php. They run flawlessly. Works the same for my shell scripts as well with just bash /directory/thisScript.sh
I added this as an answer because my reputation score won't let me add comments yet.

cronjob executing a php file

So I have a php file that executes each time it you reload it in the web browser. It uses PHPMailer, to send mail based on criteria in my db. I was attempting to use a cronjob to execute the file which I thought would basically do the same as reloading the page. The php file that I need to run in the cronjob is test.php, and its path is /var/www/html/mailer/test.php.
My cronjob is:
1 * * * * root /var/www/html/mailer/test.php >> /var/www/html/mailer/cron_status.log
and it should be throwing errors into that cron_status.log file, but its empty. I realize that this is firing every minute, but I'm just doing it to test the cronjob, and I really need to set it to 24hrs. With no error output, and no emails landing where they should be, I don't think I've properly setup my cronjob. This is my first time ever trying this. This is on a centos 7 droplet, and I've followed the tutorial from digital ocean with no success.
I need to see the php file to be sure, but you probably need to change it to this:
1 * * * * php /var/www/html/mailer/test.php >> /var/www/html/mailer/cron_status.log

Crontab process to link a php file

i have a php file named "name.php which i want to run in every 5 minutes. I want to use crontab for this function. I have found a lot of tutorial but those all are really confusing to me. Everyone seems to use a crontab file and write like so ...
*/5 * * * * wget http://www.domainname.com/cronfile.php
but i really did not get it. Suppose i have a domain name "www.mydomain.com", so if i create a php file name.php how it be directed by www.mydomain.com/name.php.
Can anyone describe shortly how i should run my php file using crontab or wget.
i am running my project in symfony.
(I'd comment if I had enough reputation to clarify if you are running the file locally - but I think that you are.)
Here's now I do it:
*/5 * * * * /usr/bin/php /home/user/cronfile.php

Cron job to execute a PHP program

I have a Linux server and in this I want to execute a cron job for sending birthday mail to all my friend with a PHP program. I want to create a php program that read data from database and send the mail.
I want to know the command of cron job to execute the program on every day automatically. I have no knowledge of Linux commands.
You will want to read up a little bit on the 'crontab' command but basically you will do this.
From a linux command prompt run the crontab command.
Then add this entry:
* * * * * php yourscript/path
You can set what time by modifying the * values. See this URL for information on that:
http://adminschoice.com/crontab-quick-reference
This is the command to add to your crontab file:
0 0 * * * /usr/bin/php /path/to/your/script.php
Adjust the paths to the PHP interpreter and your script as necessary. It will run your script every day at midnight.
This is done using a cron table in unix systems, including linux. Check out some example documentation:
http://en.wikipedia.org/wiki/Cron
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html
You'll find many more, if you google for crontab, or if you check out the man crontab pages on your linux box

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