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

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

Related

Cron job with parameters in command line

Trying to set up a couple of cron jobs in cPanel but since the system uses commandline for crons I can´t use parameters - this is a wordpress cron and relies on parameters in url.
How can i get this to work through commandline?
php -q /home/facebnzc/public_html/folkeuniversitetet/wp-cron.php?import_key=NAbeK7X&import_id=1&action=processing
This constant just enables or disables the check for events that are ready to fire. You still
add and manage events as we did up above. We just need to manually hit the wp-cron.php file in our WordPress install often enough to fire our scripts when needed.
If all you have are daily scripts, you can add a cron job like this via the crontab -e
command:
0 0 * * * wget -O - -q -t 1
http://yoursite.com/wp-cron.php?doing_wp_cron=1
Information on how to use cron can be found at its Wikipedia entry. Information on
how to use wget can be found at the wget manual.
The 0 0 * * * part of the preceding entry tells cron to execute this script at 0 minutes
on the 0th hour (midnight) every day of the week.
The wget -O - -q -t 1 http://yoursite.com/wp-cron.php?doing_wp_cron=1 part
uses the wget command to load up the wp-cron.php page in your WordPress install. The
-O - tells wget to send output to devnull, and the -q enables quiet mode. This will keep
cron from adding files to your server or emailing you the outputs of each cron run. The
-t 1 tells cron to try once. This will keep wget from hitting your server multiple times
if the first try fails. If the call to wp-cron.php is failing, the rest of your website is probably failing too; hopefully you’ve already been notified.
Be sure to change yoursite.com to your actual site URL. And finally, the ?doing_wp_cron=1 on the end of the URL is needed since wp-cron.php will check for that
$_GET parameter before running.

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.

How to run a PHP script using a DreamHost Cron Job

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

Why is my curl cron job not running?

I am trying to figure out why my curl cron job is not executing correctly. When I run it in the browser it runs just fine however if I run it in command line I get the following output. I have replaced the actual URL however the url is something like example.com/file.php?pass=password&t=d
root#low [/home/user]# sudo -u user curl URL
[1] 13959 root#low
[/home/user]# Starting backups for 0 accounts!
The output in the browser runs for all 9, 10, or however many backups I have. Am I just missing a flag in my curl request?
You are using the & sign in the command line, so the parameter t gets lost and your script does not get all its input data (and it's probably the same with your cron job, since it's executed shell-wise).
try:
curl 'url'
Checkout http://linuxcommand.org/lts0080.php, search for "Putting a program in the background" for more info on & in the shell.
I believe curl is typically located in /usr/bin/curl. Perhaps you need to run it as absolute path in your cronjob (in case /usr/bin is not contained in your default path).
This would typically be the case if it works from commandline but not from cron (as exact same command).

Running CodeIgniter cron on localhost

I'm trying to get a cron job to run every 5 min on my localhost. Using the Cronnix app I entered the following command
0,5 * * * * root curl http://localhost:8888/site/ > /dev/null
The script runs fine when I visit http://localhost:8888/site/ in my browser. I've read some stuff about getting CI to run on Cron, using wget and various other options but none make a lot of sense.
In another SO post I found the following command
wget -O - -q -t 1 http://www.example.com/cron/run
What is the "-O - -q -t 1" syntax exactly?
Are there other options?
-O - Means the output goes to stdout (-O /dev/null) would nullify any output. -q means be quiet (don't print out any progress bars), this would screw up the look of any log files. -t 1 means to only try once. If the connection fails or times out it will not try again.
See http://linux.die.net/man/1/wget for a full manual on the wget command.
Edit: just realised you're piping all this to /dev/null anyway, you may as well either omit the -O parameter or point that to /dev/null and omit the final pipe.
What I always do is use PHP in cli mode. Seems more efficient to me.
first setup a cron entry like :
*/5 * * * * /usr/bin/php /var/www/html/cronnedscript.php
cronnedscript.php should be placed in your root www folder.
then edit cronnedscript.php with:
<?php
$_GET["/mycontroller/index"] = null;
require "index.php";
?>
where mycrontroller is the CI controller you want to fire.
if you want the controller to only be run by crond ,as opposed through public www requests, add the following line to the controller and to the cronnedscript.php :
if (isset($_SERVER['REMOTE_ADDR'])) die('Permission denied');
I realize that this is a reference to Drupal, however they do a very nice job of explaining what each and every parameter is in the wget call.
Drupal Cron Explanation
If you want the more generic explanation, you can find it here.
Try this and save it by making a folder in the C drive with a .bat extension.
Then give the path of this script to task scheduler.
Then run the same.
C:\xampp\php\php-win.exe -fC:\xampp\htdocs\folder name\index.php controllername functionname

Categories