How to run a PHP script using a DreamHost Cron Job - php

I have a php script that I'd like to run everyday on my DreamHost website using a cron job. I've tested the script manually so I know it works properly.
I've tried setting up the cron job with this command line:
/usr/bin/wget -O /dev/null "http://www.mysite.org/cronjobs/cronjob.php"
along with a few other methods including this one as well:
/dh/cgi-system/php54.cgi /home/username/mysite.org/cronjobs/cronjob.php
None of these have worked and even worse, I have not received any email with the results so I have no way of knowing what went wrong.
Any idea you may have as to what isn't working would be great!

Try this command in the cpanel.
/usr/local/php5/bin/php /home/username/mysite.org/cronjobs/cronjob.php

It's been a while but since here is still no "solution" for users that might look here for a wget example here is how it works at DreamHost:
wget -q -O /dev/null http://www.domain.com/path-to-be-called

Related

Creating Cron Job on cPanel for Task Scheduling in Laravel

Pretty much the title. I am doing it as it says in the docs but it won't work. No log updates in laravel.log file either which might have helped. This is how I set up my cron job:
I also gave it my mail address where it should send the log of the job and it sometimes does do that but sometimes doesn't which I didn't quite understand why. Anyway, the mail content was simply what Laravel says when you type php artisan in the terminal. Like it shows you all the commands of Laravel.
Any idea why it doesn't work and how to fix it? Thanks!
You should to change the line of command to this:
/usr/local/bin/php /home/cpanel-user/laravel-app/artisan schedule:run >> /dev/null 2>&1

Setting up a Cron Job on CPanel to executes a PHP script

As implied in the title, the Cron Job is supposed to execute a php file (update.php, to be specific). The php file then writes to a csv file stored in the same directory.
I have the time set to * * * * * so that it executes every minute. The command is written as follows:
php -q /home//public_html/wallboard/update.php
I don't believe this is causing any errors, though it also doesn't seem to write to the CSV file. When I visit update.php in a browser, however, it executes and writes to the CSV file immediately. I'm not experienced with Cron Jobs and I'm sure there's an issue, but I don't know what exactly that issue is. Let me know if you have suggestions/questions. Any help is appreciated!
Current Command:
* * * * * usr/bin/php -q /home/<user>/public_html/wallboard/update.php
update.php:
<?php
include('lib/HelpDeskView.php');
include('lib/WallboardDisplay.php');
include('helpdesk.csv');
$helpdesk = new HelpDeskView();
$text="\r\ntest,test,test";
file_put_contents( "helpdesk.csv" , $text, FILE_APPEND);
Since your script resides in your public_html directory you can use wget for your Cron Job
wget -O - -q https://yoursite.com/wallboard/update.php
-O - output is written to the standard output in this case it will go to the email address you specify in CPanel
-q quiet mode
IMHO the best way is to contact support and ask them about command line syntax.
This is how I'm doing it at my linux server using cPanel.
This runs script.php which is stored in public root. Course, replace <username> in command line with your username.
At another server I'm using same command line with /usr/bin/php instead of php at the beginning of line, but I'm aware that not all servers use same command line. Some require php-cli in command line instead of php, some don't "like" -f argument, etc. So try various combinations.
To find more suggestions check out this SO topic too: Run a PHP file in a cron job using CPanel
Important thing: When trying different commands wait at least a minute (this case) to see if it works because Cron doesn't fire your script immediately.
Try to execute the same command in PHP CLI and check if it gives you any error, you might be missing some libraries or references required for CLI execution.
/usr/bin/php -d register_argc_argv=On /home/USERNAME/public_html/DOMAIN/artisan AMIR:HOME

What is wget cron command equals to running the code through browser

My question is I have a wget cron job setup in cpanel and it does not work.. I mean the cron job is running but the work inside code is not happening...
But when I just enter the same URL in the browser the code get executed successfully...
So can some one tell me what is exactly equal situation command in wget as like we are performing a browser request
current cron looks like this. I am using Zend php framework
wget -b http://www.**myhost**/index/db-backup
If you have curl enabled - you could just do this as your cron entry:
curl http://www.**myhost**/index/db-backup
Then it is exactly as if you hit the address in a browser
If you dont want any data dump from the cron output - you can do this
curl http://www.**myhost**/index/db-backup > /dev/null 2>&1
The http request using wget and your browser may differ. That may cause some troubles in application. You may want to debug your http request with wget --debug URL option.
For simple crawling for cron purpose wget has spider option wget --spider URL
http://www.gnu.org/software/wget/manual/wget.html

call a php page using cron jobs in direct admin

I have a php file that sends an email and it works fine when I open the page with browser. (test.php located in root of my website) But I want the page runs automatically once a day. I found that this is done using cron jobs. I searched a lot and tested a lot of commands and configurations but none of them worked.
I was using * for all time fields assuming that it will run every minute (I didn't like to wait hours to test each configuration)
I tested following commands and many others that I don't remember ):
/usr/bin/php -q http://mysite.com/test.php
/usr/bin/home/php -q http://mysite.com/test.php
/usr/local/bin/php -q http://mysite.com/test.php
/home/myID/php -q http://mysite.com/test.php
#!/usr/local/bin/php -q http://mysite.com/test.php
#!/usr/local/bin/php -q /home/myID/mysite.com/public_html/test.php
Finally, I couldn't figure out what I am doing wrong.
the host is a shared linux host running Direct Admin.
Please tell me a simple step by step guide to set the cron job to run my php file.
thank you
You don't want to call the PHP binary if you're going to run the script via http. You want to use wget (or curl). Example:
*/5 * * * * user /usr/bin/wget http://yoursite.com/cron.html -q -O /dev/null
Where user is the OS user that runs the command.
If you don't have the privileges (shared host) to do something like that, change to use a VPS instance from some provider or use an online cronjob service like https://www.setcronjob.com/.
You could open the page using lynx the command line browser:
lynx -dump http://www.google.com/ > /dev/null
Or use a service like http://cronless.com
Update:
If you setup a cron job in your control panel and it didn't run then most probably your web host disabled it.
My advice is to use a cron job service like cronless.

Cannot execute crontab command from a php script...from shared host

I'm running an application where I need to execute the cron job, once a form is submitted,contains more than 1 lac records in a loop(its on-demand execution of cron job and deletes the job once finished).
I'm using php, I tried to configure the job through cpanel as a test and it works...the command was.."/ramdisk/bin/php5 -f /home/user/public_html/domain/cron.php -q", it worked fine.
But when I tried to run the same job with the exec() of php, like I wrote this whole command to a file (I do not know where the original crontab file is located otherwise could have written to it, please suggest a way to find its location) and ran that file like "exec("crontab /home/user/cron/Feed_cron"); ", in this cron is not working...
I doubted whether the crontab command will not work for particular user.. I tried it from the "root" user....which is the root user....tried the command via SSH or Putty and the response was "command not found". Please find a solution for this, also please give me an idea whether my concept works fine...
please suggest a way to find its location
Try
whereis crontab

Categories