Previously I wrote about a method of hooking up an existing site with the Drupal backend. That will work fine if the request comes from the browser, but for a script you will need an extra little bit of configuration.
In conjuction with initialise_drupal_bootstrap() (a function provided in the previous post), you will need to call the following.
01.
function
initialise_for_script(
$server_address
=
'yoursite.com'
) {
02.
global
$_SERVER
;
03.
04.
// define default settings
05.
$_SERVER
[
'HTTP_HOST'
] =
$server_address
;
06.
$_SERVER
[
'PHP_SELF'
] =
'/index.php'
;
07.
$_SERVER
[
'REMOTE_ADDR'
] =
'127.0.0.1'
;
08.
$_SERVER
[
'SERVER_SOFTWARE'
] =
'PHP CLI'
;
09.
$_SERVER
[
'REQUEST_METHOD'
] =
'GET'
;
10.
$_SERVER
[
'QUERY_STRING'
] =
''
;
11.
$_SERVER
[
'PHP_SELF'
] =
$_SERVER
[
'REQUEST_URI'
] =
'/'
;
12.
}
When using the bootstrappers, your script would look something like this:
01.
/*
02.
* Run this from your Drupal folder.
03.
* Usage: php scripts/mailout.php
04.
*/
05.
06.
require_once
(
'./scripts/drupal_bootstrap.inc'
);
07.
initialise_for_script(
'examplesite.com'
);
08.
initialise_drupal_bootstrap();
09.
10.
if
(function_exists(mailout_loop')) {
11.
mailout_loop();
12.
}