How to run a PHP script with parameters using CRON in mybox

On this page
  1. Why parameters are not supported in CRON
  2. Workaround: using a wrapper PHP file
  3. Step 1: Create a wrapper file
  4. Step 2: Adjust your main script
  5. Step 3: Add the wrapper file to CRON
  6. Practical implications
  7. Summary

In mybox, the CRON job manager does not support passing parameters directly to PHP scripts. This means you cannot define command-line arguments in a standard CRON entry.

To achieve the same result, you can use a simple workaround by creating an intermediate PHP file that sets parameters before including the target script.

Why parameters are not supported in CRON

CRON tasks execute predefined commands at scheduled intervals. In this environment, the CRON manager does not interpret additional script arguments, which limits direct parameter passing to PHP scripts.

To work around this limitation, parameters can be simulated inside PHP.

Workaround: using a wrapper PHP file

Instead of calling the target script directly, you create a second PHP file that defines the parameters and then loads the main script.

Step 1: Create a wrapper file

Create a new PHP file, for example:

cron-wrapper.php

Add the following content:

<?php

$_SERVER["argv"][1] = "13"; // first parameter example
$_SERVER["argv"][2] = "13"; // second parameter example

// add more parameters if needed
// $_SERVER["argv"][3] = "value";

include "script.php"; // target script

This file simulates CLI-style arguments inside the PHP environment.

Step 2: Adjust your main script

Your main script (script.php) can now access these values using:

$_SERVER["argv"]

This allows the script to behave as if it was executed with parameters.

Step 3: Add the wrapper file to CRON

In the mybox panel:

  1. Open the CRON manager
  2. Create a new CRON job
  3. Select or specify the wrapper file (cron-wrapper.php)
  4. Set the desired execution schedule
  5. Save the task

The CRON system will now execute the wrapper file, which passes parameters to the main script.

Practical implications

This approach:

  • allows simulated parameter passing in CRON
  • keeps CRON configuration simple
  • centralizes logic inside PHP files

However, parameters must be defined manually in the wrapper file, as CRON itself does not pass dynamic arguments.

Summary

Since CRON in mybox does not support direct parameter passing to PHP scripts, a wrapper PHP file can be used to define parameters and include the main script. This allows controlled execution of scripts with custom values.

Didn't find an answer?

Our support team is here for you 24/7 – write to us and we will help you sort it out.