• Hi there,

    We run WordPress’s Cron function via an external scheduler as documented here. However, since upgrading to PHP 8.0 the cron job output now has the following warning in it;

    PHP Warning:  Undefined array key "SERVER_NAME" in /home/sites/REMOVED/public_html/wp-content/mu-plugins/PluginOrganizerMU.class.php on line 20

    Looking at the code on line 20 in the version of the plugin we’re currently using (10.1.7), the line is;

    $this->httpHostName = $_SERVER['SERVER_NAME'];
    

    As we’re invoking the cron script directly via the php CLI command, presumably the $_SERVER array doesn’t have aSERVER_NAME key like it does when PHP is invoked via a web server.

    For now, i’ve manually prefixed $_SERVER['SERVER_NAME'] with an @ to suppress the warning, but this will be wiped out on any future upgrades.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Jeff Sterup

    (@foomagoo)

    I’m wondering if I need to add an option to not execute Plugin Organizer when cron is being called. I could also do a check to see if that array key is set and not execute the function because without the server name the functionality of Plugin Organizer wouldn’t work anyway.

    Plugin Author Jeff Sterup

    (@foomagoo)

    Actually I don’t need to rely on that variable. I can access the wpurl option within the MU class. I didn’t think it would be available that early but I’m able to use that. I have released version 10.1.8 which should get rid of those warnings.

    I seem to have an issue with the latest change. While the code may be able to get the url, it seems to cause issues in which this plugin isn’t limiting plugins as it once was. If I revert back to 10.1.7, the plugins disabled in the filters are working again, but not when 10.1.8 is installed.

    Plugin Author Jeff Sterup

    (@foomagoo)

    @rbaugh I just released 10.1.9 that reverts a change that was probably enabling plugins where you had disabled them.

    Jeff,
    The changes seems to get things back, but I think the issue is in the get_bloginfo function. When I applied 10.1.8 and had the issue, I just changed the code back in the MU class file and everything started working again. I see you added checks for the Server variable first and then resort to the get_bloginfo function, but I wonder if that may cause the same issues in which this still ignores the code this plugin provides and loads all plugins as default. It may not be needed for a CLI call, but just sharing. I haven’t dug in further, but wonder if somehow the get_bloginfo is loading in all plugins as that line causes your plugin to not function as needed. If I just replace the if statements with the one line from 10.1.8 it breaks the plugin again.

    Plugin Author Jeff Sterup

    (@foomagoo)

    The issue is that your site has a different value for the server variable and wpurl option. If you print both within a page you’ll see what I mean. Your filters were created using the server variable and so it broke for you. My servers have the same value for both so it worked for me using both.

    Plugin Author Jeff Sterup

    (@foomagoo)

    @rbaugh I think I see exactly what I did. Does your site have a path after the domain name? I didn’t complete the regex properly to account for sites that have a path like https://www.sterupdesign.com/this/is/the/path/. I was just expecting https://www.sterupdesign.com/ which would have left your siteURL variable with a path on it and would have broken the permalink match to find your disabled/enabled plugins.

    • This reply was modified 2 years, 1 month ago by Jeff Sterup.
    rbaugh

    (@rbaugh)

    Sorry, I didn’t get any notices of your replies. The site does not have any folders as part of the root url. It is just the domain.

    When I was trying to figure out what was going on I was outputting the value of the url to check it as I was under the same impression as you. That maybe the url wasn’t matching. But it was matching. I was outputting the value of the permalink in the set_requested_permalink function.

    I went back and copied this value from the logs I still have around and it is matching the value that was set in the filter rule.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Undefined array key “SERVER_NAME” when running under external Cron’ is closed to new replies.