WordPress multisite breaks including / require of wp-load.php

I get the following error after moving to multisite when running my cronjob:

Notice: Undefined index: HTTP_HOST in /var/www/html/myapp/wp-includes/ms-settings.php on line 38

Call Stack:
    0.0009     392912   1. {main}() /var/www/html/myapp/wp-content/themes/fundingpress-child/test.php:0
    0.0010     395888   2. require('/var/www/html/myapp/wp-content/themes/fundingpress-child/bootstrap.php') /var/www/html/myapp/wp-content/themes/fundingpress-child/test.php:6
    0.0065     687056   3. require_once('/var/www/html/myapp/wp-load.php') /var/www/html/myapp/wp-content/themes/fundingpress-child/bootstrap.php:7
    0.0066     699048   4. require_once('/var/www/html/myapp/wp-config.php') /var/www/html/myapp/wp-load.php:37
    0.0074     800592   5. require_once('/var/www/html/myapp/wp-settings.php') /var/www/html/myapp/wp-config.php:89
    0.0329    3665088   6. require('/var/www/html/myapp/wp-includes/ms-settings.php') /var/www/html/myapp/wp-settings.php:103


Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/myapp/wp-includes/ms-settings.php:38) in /var/www/html/myapp/wp-includes/ms-settings.php on line 187

Call Stack:
    0.0009     392912   1. {main}() /var/www/html/myapp/wp-content/themes/fundingpress-child/test.php:0
    0.0010     395888   2. require('/var/www/html/myapp/wp-content/themes/fundingpress-child/bootstrap.php') /var/www/html/myapp/wp-content/themes/fundingpress-child/test.php:6
    0.0065     687056   3. require_once('/var/www/html/myapp/wp-load.php') /var/www/html/myapp/wp-content/themes/fundingpress-child/bootstrap.php:7
    0.0066     699048   4. require_once('/var/www/html/myapp/wp-config.php') /var/www/html/myapp/wp-load.php:37
    0.0074     800592   5. require_once('/var/www/html/myapp/wp-settings.php') /var/www/html/myapp/wp-config.php:89
    0.0329    3665088   6. require('/var/www/html/myapp/wp-includes/ms-settings.php') /var/www/html/myapp/wp-settings.php:103
    0.0346    3804784   7. header() /var/www/html/myapp/wp-includes/ms-settings.php:187

My cronjob php file:

Read More
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);
require_once(  __DIR__ .'/../../../wp-load.php' );
?>
bippo
<?php

$myfile = fopen(__DIR__ . "/xxxxxxxxxxxxxxxxxxxxnewfile.txt", "w") or die("Unable to open file!");
$txt = "John Doen";
fwrite($myfile, $txt);
$txt = "Jane Doen";
fwrite($myfile, $txt);
fclose($myfile);

die("bb");

And yes: this cronjob PHP file is just an example. I need access to all WordPress functions. If I remove the wp-load.php call, this works. When my site was not multisite, this works. Now, it doesn’t work for said error.

Related posts

Leave a Reply

1 comment

  1.   global $_SERVER;
      $_SERVER['HTTP_HOST'] = 'www.mydomain.com';
      $_SERVER['REQUEST_URI'] = '/';
      require_once(  __DIR__ .'/../../../wp-load.php' );
    

    seems to have fixed my issues where mydomain should be your actual domain (localhost.localdomain probably when using locally or localhost, i used a local virtual host )