How to call PHP/Perl/ASP.NET scripts from scheduled tasks

Created:

2016-11-16 12:48:52 UTC

Modified:

2017-04-24 11:21:51 UTC

1

Was this article helpful?


Have more questions?

Submit a request

How to call PHP/Perl/ASP.NET scripts from scheduled tasks

Applicable to:

  • Plesk 10.4 for Windows
  • Plesk 12.5 for Linux
  • Plesk Onyx for Linux
  • Plesk Onyx for Windows
  • Plesk 11.5 for Windows
  • Plesk 11.5 for Linux
  • Plesk 12.0 for Windows
  • Plesk 10.x and below for Linux

Question

How do I call my PHP/Perl/ASP.NET/other script from a scheduled task?

Answer

Run script with appropriate program

If the script can be executed with an interpreter (e.g., PHP or Perl) and does not require parameters defined in an HTTP request, create a new scheduled task that calls the script interpreter with the path to the script as an option:

/usr/bin/perl /var/www/vhosts/domain.test/cgi-bin/crontasks/cron.pl

On Windows:

Path to executable file : "C:\\Program Files (x86)\\Parallels\\Plesk\\Additional\\Perl\\bin\\perl.exe" Arguments: "C:\\Inetpub\\vhosts\\domain.test\\cgi-bin\\crontasks\\cron.pl"

Make HTTP request to call the script

Another way to call the script is to create a task that will perform an HTTP request to the required script:

/usr/bin/wget -qq -O /dev/null http://domain.test/script.php

or

/usr/bin/curl -sL http://domain.test/script.php >/dev/null

On Windows, it is possible to make an HTTP request through PowerShell:

Path to executable file: C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe
Arguments: -c "(new-object system.net.webclient).downloadstring('http://domain.test/script.aspx')"

Important notes

  1. Paths to utilities should be absolute, i.e., /usr/bin/wget instead of just wget .
  2. If a domain is set up to allow shell access via a chrooted shell (on Linux), then the commands defined in cronjobs will be looked up inside the chrooted environment set up in the virtual host directory. Such an environment contains a minimal set of utilities and language interpreters (Perl/PHP), but network utilities (curl/wget) are not included. As such, the command will fail to run. To avoid this, you may set up the server to execute scheduled tasks for all users in the global server scope using the instructions provided in this KB article: \#213921825

See also

For more information on how to schedule tasks, read the chapter Scheduling Tasks in the Plesk Administrator's Guide .

Have more questions? Submit a request
Please sign in to leave a comment.