Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Fatal error from 'Create webp files upon request? ' Live Test #379

Closed
andrewfleming opened this issue Oct 10, 2019 · 4 comments · Fixed by #398
Closed

PHP Fatal error from 'Create webp files upon request? ' Live Test #379

andrewfleming opened this issue Oct 10, 2019 · 4 comments · Fixed by #398
Milestone

Comments

@andrewfleming
Copy link

When usig the 'Create webp files upon request? ' Live Test button I get the following fatal error.

[10-Oct-2019 12:37:26 UTC] PHP Notice:  Undefined index: path in /wp-content/plugins/webp-express/lib/classes/AlterHtmlHelper.php on line 73
[10-Oct-2019 12:37:26 UTC] PHP Fatal error:  Uncaught Error: Cannot use object of type WP_Error as array in /wp-content/plugins/webp-express/lib/classes/SelfTestHelper.php:199
Stack trace:
#0 /wp-content/plugins/webp-express/lib/classes/SelfTestRedirectToWebPRealizer.php(58): WebPExpress\SelfTestHelper::remoteGet(false, Array)
#1 /wp-content/plugins/webp-express/lib/classes/SelfTestRedirectAbstract.php(38): WebPExpress\SelfTestRedirectToWebPRealizer->runTestForImageType('index', 'jpeg')
#2 /wp-content/plugins/webp-express/lib/classes/SelfTestRedirectAbstract.php(74): WebPExpress\SelfTestRedirectAbstract->doRunTestForRoot('index')
#3 //wp-content/plugins/webp-express/lib/classes/SelfTestRedirectAbstract.php(107): WebPExpress\SelfTestRedirectAbstract->runTestForRoot('index')
#4 /wp-content/plugins/webp-express/lib/classes/SelfTestRedirectToWebPRealizer.php(222): WebPExpress\SelfT in /home/betset/dev.betset.com.au/wp-content/plugins/webp-express/lib/classes/SelfTestHelper.php on line 199

System info

System info:
- PHP version: 7.3.10
- OS: Linux
- Server software: LiteSpeed
- Document Root status: Available and its "realpath" is available too. Can be used for structuring cache dir.
- Document Root: /home/betset/dev.betset.com.au
- Document Root: Available and its "realpath" is available too. Can be used for structuring cache dir.
- Apache module "mod_rewrite" enabled?: yes
- Apache module "mod_headers" enabled?: yes
Wordpress info:
- Version: 5.2.3
- Multisite?: no
- Is wp-content moved?: no
- Is uploads moved out of wp-content?: no
- Is plugins moved out of wp-content?: no

Image roots (absolute paths)
uploads: /home/betset/dev.betset.com.au/wp-content/uploads
themes: /home/betset/dev.betset.com.au/wp-content/themes
plugins: /home/betset/dev.betset.com.au/wp-content/plugins
wp-content: /home/betset/dev.betset.com.au/wp-content
index: /home/betset/dev.betset.com.au
Image roots (relative to document root)
uploads: wp-content/uploads
themes: wp-content/themes
plugins: wp-content/plugins
wp-content: wp-content
index: .
Image roots (URLs)
uploads: https://dev.betset.com.au/wp-content/uploads
themes: https://dev.betset.com.au/wp-content/themes
plugins: https://dev.betset.com.au/wp-content/plugins
wp-content: https://dev.betset.com.au/wp-content
index: https://dev.betset.com.au
WebP Express configuration info:
- Destination folder: separate
- Destination extension: append
- Destination structure: doc-root
(To view all configuration, take a look at the config file, which is stored in /home/betset/dev.betset.com.au/wp-content/webp-express/config/config.json)
Live tests of .htaccess capabilities:
- mod_rewrite working?: yes
- mod_header working?: no
- passing variables from .htaccess to PHP script through environment variable working?: yes
.htaccess files that WebP Express have placed rules in the following files:
- /home/betset/dev.betset.com.au/wp-content/uploads/.htaccess
- /home/betset/dev.betset.com.au/wp-content/themes/.htaccess
- /home/betset/dev.betset.com.au/wp-content/plugins/.htaccess
- /home/betset/dev.betset.com.au/wp-content/.htaccess
- /home/betset/dev.betset.com.au/wp-content/webp-express/webp-images/.htaccess
@solucionesuno
Copy link

same problem here

@gaswirth
Copy link

+1

@pimschaaf
Copy link

pimschaaf commented Jan 19, 2020

+1

PHP Fatal error:  Uncaught Error: Cannot use object of type WP_Error as array in webp-express/lib/classes/SelfTestHelper.php:199
Stack trace:
#0 webp-express/lib/classes/SelfTestRedirectToWebPRealizer.php(58): WebPExpress\\SelfTestHelper::remoteGet('...', Array)
#1 webp-express/lib/classes/SelfTestRedirectAbstract.php(38): WebPExpress\\SelfTestRedirectToWebPRealizer->runTestForImageType('uploads', 'jpeg')
#2 webp-express/lib/classes/SelfTestRedirectAbstract.php(74): WebPExpress\\SelfTestRedirectAbstract->doRunTestForRoot('uploads')
#3 webp-express/lib/classes/SelfTestRedirectAbstract.php(107): WebPExpress\\SelfTestRedirectAbstract->runTestForRoot('uploads')
#4 webp-express/lib/classes/SelfTestRedir in webp-express/lib/classes/SelfTestHelper.php on line 199, referer: /wp-admin/options-general.php?page=webp_express_settings_page

@rrikesh
Copy link
Contributor

rrikesh commented Feb 7, 2020

I'm also getting that issue but I found why the error was being triggered. I'm not sure if you all are having the same issue but here's how to debug it:

[07-Feb-2020 02:04:10 UTC] PHP Fatal error:  Uncaught Error: Cannot use object of type WP_Error as array in /Users/xxxxxxxx/xxxxxx/xxxxxx/wp-content/plugins/webp-express/lib/classes/SelfTestHelper.php:199

If you look in the SelfTestHelper at line 199, you'll see this code:

$wpResult = wp_remote_get($requestUrl, $args);
if (!isset($wpResult['headers'])) { // <--- line 199
    $wpResult['headers'] = [];
}
$results[] = $wpResult;
if (is_wp_error($wpResult)) {
    $log[] = 'The remote request errored';
    return [false, $log, $results];
}

It tells you that your wp_remote_get() request failed and you got the WP_Error object in $wpResult. So trying to read $wpResult['headers'] is triggering the fatal error. The is_wp_error() check should have been done before trying to access $wpResult['headers'].

To debug it, I have added a trigger_error() to show me what went wrong in the request:

$wpResult = wp_remote_get($requestUrl, $args);
trigger_error( print_r($wpResult, true) ); // <--- Temporarily add this line while debugging
if (!isset($wpResult['headers'])) {
    $wpResult['headers'] = [];
}

When I checked the error log, I could then see what happened:

[07-Feb-2020 02:18:04 UTC] PHP Notice:  WP_Error Object
(
    [errors] => Array
        (
            [http_request_failed] => Array
                (
                    [0] => cURL error 60: SSL certificate problem: unable to get local issuer certificate
                )

        )

    [error_data] => Array
        (
        )

)

I'm using a self-signed certificate on MAMP Pro and that's causing the issue. To double check, I ran a curl on terminal:

curl -v https://xxxxxxx.xxx
*   Trying ::1...
* TCP_NODELAY set
* Connected to xxxxxxx.xxx (::1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS alert, unknown CA (560):
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

That's the error. Running curl -vk https://xxxxxxx.xxx should fix the issue. the k flag allows for an insecure connection. The wp_remote_get() equivalent is using sslverify => false as an argument. I've added that at the start of the function and got no errors when I tested:

$log = [];
$args['redirection'] = 0;
$args['sslverify'] = false; // <-- Add this line.

Since I need this only for local development (production will have good certificates), I would recommend wrapping it in some flag that will run only on your development machine. For example:

$log = [];
$args['redirection'] = 0;
if( defined('WP_DEBUG') && WP_DEBUG ){
    $args['sslverify'] = false;
}

All of the three Live Tests now run without issues on my local machine.

rosell-dk added a commit that referenced this issue Jun 26, 2020
Prevent Fatal Errors with unverified certificates - Fix #379
@rosell-dk rosell-dk added this to the 0.17.4 milestone Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants