0

I have a simply php script on my server and want it to be run every 2 minutes using a cron job.

*/2 *   *   *   *   http://mydomain.com/_adder.php

I suspect the command syntax is wrong.

Do I need to add a command before the script url? Another way to run the script?

Any help is very much appreciated.

umläute
  • 28,885
  • 9
  • 68
  • 122
user586011
  • 1,908
  • 4
  • 18
  • 29

3 Answers3

2

the cron-job will simply execute a program on the (local) machine.

a URL is NOT a program. it's a link to a ressource.

whether this ressource triggers a PHP-script execution is not of cron's business.

in any case, you could run a cron-job that will periodically visit a given URL. e.g. using the wget command (a "non-interactive web-page downloader")

*/2 *   *   *   *   wget --quiet -O /dev/null http://mydomain.com/_adder.php
umläute
  • 28,885
  • 9
  • 68
  • 122
  • I think the user wants to execute a script on his own machine – Paco Oct 06 '13 at 18:36
  • @Paco probably; he is a bit contradictory here ("my server" vs giving a public URL) – umläute Oct 06 '13 at 18:39
  • @Paco... by my sever, I mean a public URL that I connect to via FTP. When the URL is loaded the script runs automatically. – user586011 Oct 06 '13 at 20:17
  • @user586011 in any case, regardless of `http` or `ftp` the solution provided will "load" the script and thus trigger it's execution – umläute Oct 08 '13 at 07:43
1

you can do it as umläute suggest, but being a local file it's actually faster to access from command line php like this:

*/2 * * * * php /path/to/file/_adder.php

there are differences running a script from the command line vs via a browser that may effect the script.

you may need the full path to php on some systems

  • website.com/path/_adder.php is the direct path to the script – user586011 Oct 06 '13 at 19:54
  • starting with / it should be the full server file path, but i have no way of knowing what that is in your case –  Oct 06 '13 at 19:55
  • @user586011 you *cannot* run a script via php that is located on a remote server. URLs starting with `http://` or `ftp://` are *always* considered on a *remote* server as you can only access them via the network - even if the machine is physically the same as the one you are working on. – umläute Oct 08 '13 at 07:42
0

use php-cgi to make GET request similar to a web browser .

/usr/bin/php-cgi   /your_path/_adder.php

if you're using Linux you can use which php-cgi to locate for php-cgi or search for php7.2-cgi if php 7.2 installed on your machine or search using different version . for Windows users search for php-cgi.exe .

Salem
  • 654
  • 7
  • 24