App for Cloudflare® Pro

App for Cloudflare® Pro 1.9.2

New Update gave 500 server error

Ok, so with the two lines left commented out and the new code added, everything continues to work. With the new code and the two lines uncommented, the 500 error returns.
 
Ok, so with the two lines left commented out and the new code added, everything continues to work. With the new code and the two lines uncommented, the 500 error returns.

Anything if the guts of the methods are wrapped in try/catch?
PHP:
    public function handleScriptLoaderTag($tag, $handle, $src)
    {
        try {
            if (is_string($src) && strlen($src) > 3)
            {
                $this->preload['<' . sanitize_url($src) . '>;as=script;rel=preload'] = true;
            }
        }
        catch(\Exception $e){
            wp_die($e->getMessage());
        }
        return $tag;
    }

    public function handleStyleLoaderTag($tag, $handle, $href)
    {
        try {
            if (is_string($href) && strlen($href) > 3 && strpos($href, '/ie.css') === false)
            {
                $this->preload['<' . sanitize_url($href) . '>;as=style;rel=preload'] = true;
            }
        }
        catch(\Exception $e){
            wp_die($e->getMessage());
        }
        return $tag;
    }
 
Anything if the guts of the methods are wrapped in try/catch?
PHP:
    public function handleScriptLoaderTag($tag, $handle, $src)
    {
        try {
            if (is_string($src) && strlen($src) > 3)
            {
                $this->preload['<' . sanitize_url($src) . '>;as=script;rel=preload'] = true;
            }
        }
        catch(\Exception $e){
            wp_die($e->getMessage());
        }
        return $tag;
    }

    public function handleStyleLoaderTag($tag, $handle, $href)
    {
        try {
            if (is_string($href) && strlen($href) > 3 && strpos($href, '/ie.css') === false)
            {
                $this->preload['<' . sanitize_url($href) . '>;as=style;rel=preload'] = true;
            }
        }
        catch(\Exception $e){
            wp_die($e->getMessage());
        }
        return $tag;
    }
Unfortunately not no. I can only get it working if I leave those two original lines commented out.
 
What happens if you comment just this line (none of the other ones)?

PHP:
// add_action('wp_print_footer_scripts', [$this, 'handlePrintFooterScripts'], 9999999);
 
I've had a look through the various logs, and I'm not seeing any errors that relate to the plugin. Speaking of plugins, I've been doing some fiddling around deactivating everything and then re-activating to see what might happen. Unsurprisingly, with every plugin deactivated except for AppForCF, everything worked. However, there are a few plugins that, when enabled as well, caused the 500 error to return. Some examples are: Fluent Forms Pro, Kadence Blocks Pro, and WooCommerce.

Leave it with me while I try your most recent two posts.
 
Do you have an example URL of your site (even if the plugin is disabled currently)? One possibility might be that your web server has a limitation on the size of the HTTP response headers (normally there's a limitation on the request headers, but not response headers). If that's the case, then the issue would be upstream of WordPress/PHP stack, so PHP isn't going to throw an error (would be coming from web server itself). Seeing combination of plugins causing the issue, but not individual ones may be something along the lines of different plugins are adding HTTP response headers, but it's only when the total size of all the response headers gets larger than a certain amount, the web server decides it's not doing it.

...although that wouldn't explain it happening even with the preload resources option disabled (headers are only added when it's enabled). So maybe that whole thought is irrelevant.

Still would be interested in the URL if possible... curious if there's an insane amount of individual JavaScript and CSS files that might be too many to realistically preload.
 
Do you have an example URL of your site (even if the plugin is disabled currently)? One possibility might be that your web server has a limitation on the size of the HTTP response headers (normally there's a limitation on the request headers, but not response headers). If that's the case, then the issue would be upstream of WordPress/PHP stack, so PHP isn't going to throw an error (would be coming from web server itself). Seeing combination of plugins causing the issue, but not individual ones may be something along the lines of different plugins are adding HTTP response headers, but it's only when the total size of all the response headers gets larger than a certain amount, the web server decides it's not doing it.

...although that wouldn't explain it happening even with the preload resources option disabled (headers are only added when it's enabled). So maybe that whole thought is irrelevant.

Still would be interested in the URL if possible... curious if there's an insane amount of individual JavaScript and CSS files that might be too many to realistically preload.
staging.thecuriouscreative.co.uk

everything except for Flyingpress is loaded currently, so no doubt you'll have a field-day!
 
staging.thecuriouscreative.co.uk

everything except for Flyingpress is loaded currently, so no doubt you'll have a field-day!
So I was able to get a 502 error from Cloudflare... Basically I took all the scripts and CSS you have on that page and then preloaded each of them 10 times. Was just seeing if Cloudflare's side has a limit on HTTP response headers (apparently they do when it gets very, very big).

Given that, it probably does make sense to limit how many resources are preloaded (regardless if the limitation is certain web server configs or a proxy like Cloudflare). So one more thing to test if you have the time...

Change this:
PHP:
header('Link: ' . implode(',', array_keys($this->preload)), false);

...to this:
PHP:
header('Link: ' . implode(',', array_slice(array_keys($this->preload), 0, 10)), false);

Will limit preloading to 10 items (a site is going to start seeing diminishing returns if they are preloading a zillion files even if their site needs them).
 
Yes, it looks like everything's working as it should be. I've still got some of the edits in the pub file such as the 'try' and 'catch' additions. Would you recommend that I just alter the header('link:' line of code and revert the rest to how they were originally?
 
Thank you so much for your help and prompt responses with this, much appreciated. The new update has been installed and all appears to be working. 😎
 
Thank you so much for your help and prompt responses with this, much appreciated. The new update has been installed and all appears to be working. 😎
No worries… and also sorry about the trouble.

Makes sense now why only a couple people saw it and I couldn’t replicate it though (only on sites loading a ton of individual JavaScript and CSS files causing the headers in HTTP response to be overloaded… not technically a PHP error to be logged or seen). 😬
 
Back
Top