2

The server my site is on cannot use curl, wget or lynx to call the external cron address (eg http://example.com/cron/cron_key)

Is it possible to use php to 'run' the cron from inside the server.

I'm was thinking something like php -f /home/docroot/core/Drupal/Cron.php with a query string for the cron key, but I notice there isn't a query string as in Drupal 7.

I cannot use Drush since it's not installed on the prod servers.

I also cannot use a third party external cron service.

Any ideas?

2 Answers 2

1

a way to do that :

create customcron.php in the drupal root with the content :

<?php

use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;

$autoloader = require_once 'autoload.php';

$kernel = new DrupalKernel('prod', $autoloader);

$request = Request::createFromGlobals();
$response = $kernel->handle($request);

// Load cron service and run cron.
\Drupal::service('cron')->run();

$kernel->terminate($request, $response);

then run :

php customcron.php

i would not let the file customcron.php in the root because anybody could then execute it from the browser.

A simple way to avoid that is moving the file customcron.php to drupal root only for the time you execute it or maybe have an unguessable file name instead of customcron.php

-1

In general, using Drush to run cron via drush cron or Drupal Console cron:execute drupal cron:execute would be a first suggestion.

If you are interested in command line, it's likely that Drush and Drupal Console will become valuable tools for you, so to not have them because they aren't on prod is a bummer.

There is also the concept of site aliases in drush that can work on remote servers.

1
  • I just noticed the part about "drush is not installed" so...updated to clarify my answer.
    – greggles
    Commented Nov 16, 2018 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.