adding_custom_php_to_drupal_chron_directory
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
adding_custom_php_to_drupal_chron_directory [2017/08/18 08:54] – created tomgle | adding_custom_php_to_drupal_chron_directory [2017/08/18 09:09] (current) – tomgle | ||
---|---|---|---|
Line 2: | Line 2: | ||
- | 10 | + | From Stackoverflow: |
- | down vote | + | |
If you need to run code just once, you can do it without installing any module, including the Devel module. | If you need to run code just once, you can do it without installing any module, including the Devel module. | ||
Write a PHP file (e.g. tasks.php), put it where the cron.php file that comes with Drupal is, and add the following code. | Write a PHP file (e.g. tasks.php), put it where the cron.php file that comes with Drupal is, and add the following code. | ||
+ | < | ||
/** | /** | ||
* Root directory of Drupal installation. | * Root directory of Drupal installation. | ||
*/ | */ | ||
define(' | define(' | ||
+ | | ||
include_once DRUPAL_ROOT . '/ | include_once DRUPAL_ROOT . '/ | ||
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); | drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); | ||
- | drupal_set_time_limit(240); | + | drupal_set_time_limit(240); |
+ | |||
+ | // Your code here. | ||
+ | </ | ||
- | // Your code here. | ||
If you are already using Drush for maintaining/ | If you are already using Drush for maintaining/ | ||
- | + | < | |
- | # | + | # |
- | + | ||
- | // Your code here. | + | // Your code here. |
- | // Access the options with drush_get_option(), | + | // Access the options with drush_get_option(), |
+ | |||
+ | </ | ||
You could also execute a PHP script with drush php-eval, for example: | You could also execute a PHP script with drush php-eval, for example: | ||
- | drush php-eval 'print time();' | + | |
I would create a Drush script, but if you cannot install Drush, or you need to execute PHP code from the browser, the first method works fine. | I would create a Drush script, but if you cannot install Drush, or you need to execute PHP code from the browser, the first method works fine. |
adding_custom_php_to_drupal_chron_directory.1503060877.txt.gz · Last modified: 2017/08/18 08:54 by tomgle