I'm deeply confused by this one: I have a WordPress install on a Media Temple GS [one of many which work fine and are configured almost exactly the same] which is occasionally giving me 404s sitewide. When this happens I get 3 errors together in my PHP error log:
[01-Nov-2013 22:20:50 UTC] PHP Notice: Trying to get property of non-object in /nfs/---/---/mnt/---/domains/---.---/html/wp-includes/post-template.php on line 275
[01-Nov-2013 22:20:50 UTC] PHP Notice: Trying to get property of non-object in /nfs/---/---/mnt/---/domains/---.---/html/wp-includes/post-template.php on line 209
[01-Nov-2013 22:20:50 UTC] PHP Notice: Trying to get property of non-object in /nfs/---/---/mnt/---/domains/---.---/html/wp-includes/post-template.php on line 29
The first two relate to the $post
object & the 3rd to this: get_post()->ID;
Which I think is the creation of the $post
object.
I have two of these identical trios of error messages almost exactly 25 minutes apart [off by 2s].
I've tried MT support but they think it must be a WP error. I'm running the latest version of WP but have experienced this problem with earlier versions.
I had 2 plugins enabled: W3 Total Cache & AJAX Thumbnail Rebuild
I've tested with and without the cache plugin and the problem persists. I've just disabled the thumbnail plug to see if it makes any difference.
Please help this is driving me insane! [and I wanted to publicly launch this site today]
EDIT
I should have also mentioned that I have seen this error on some but not all of the other wordpress installs on this server. I think but cannot be 100% sure, that those showing errors are newer installs than the ones working fine. Though all installs are fully updated.
EDIT2
I'm just working on another WP project and realised at least what those 3 errors mean. I can reproduce exactly those three php errors by going to the index page of a custom post type that does not exist. However this doesn't explain why that would cause the 404 in this question, especially as it doesn't just happen only on custom post type index pages. However I think this must be related to custom post types in some way.
I'm deeply confused by this one: I have a WordPress install on a Media Temple GS [one of many which work fine and are configured almost exactly the same] which is occasionally giving me 404s sitewide. When this happens I get 3 errors together in my PHP error log:
[01-Nov-2013 22:20:50 UTC] PHP Notice: Trying to get property of non-object in /nfs/---/---/mnt/---/domains/---.---/html/wp-includes/post-template.php on line 275
[01-Nov-2013 22:20:50 UTC] PHP Notice: Trying to get property of non-object in /nfs/---/---/mnt/---/domains/---.---/html/wp-includes/post-template.php on line 209
[01-Nov-2013 22:20:50 UTC] PHP Notice: Trying to get property of non-object in /nfs/---/---/mnt/---/domains/---.---/html/wp-includes/post-template.php on line 29
The first two relate to the $post
object & the 3rd to this: get_post()->ID;
Which I think is the creation of the $post
object.
I have two of these identical trios of error messages almost exactly 25 minutes apart [off by 2s].
I've tried MT support but they think it must be a WP error. I'm running the latest version of WP but have experienced this problem with earlier versions.
I had 2 plugins enabled: W3 Total Cache & AJAX Thumbnail Rebuild
I've tested with and without the cache plugin and the problem persists. I've just disabled the thumbnail plug to see if it makes any difference.
Please help this is driving me insane! [and I wanted to publicly launch this site today]
EDIT
I should have also mentioned that I have seen this error on some but not all of the other wordpress installs on this server. I think but cannot be 100% sure, that those showing errors are newer installs than the ones working fine. Though all installs are fully updated.
EDIT2
I'm just working on another WP project and realised at least what those 3 errors mean. I can reproduce exactly those three php errors by going to the index page of a custom post type that does not exist. However this doesn't explain why that would cause the 404 in this question, especially as it doesn't just happen only on custom post type index pages. However I think this must be related to custom post types in some way.
Share Improve this question edited Dec 9, 2013 at 20:28 iiz asked Nov 1, 2013 at 22:35 iiziiz 1415 bronze badges 17- Sidewide means on all pages/post/categories but not in wp-admin, so basically any frontend page? ps: disabling the W3TC plugin doesn't remove all caching functionality immediately. The better way is to disable caching on the main options page of the plugin and this really sounds like a caching / cache configuration issue. – s1lv3r Commented Nov 2, 2013 at 9:44
- Yes sidewide means any frontend page but nothing in wp-admin. I don't think it can have anything to do with the W3 Cache plugin as I was having this problem occasionally in development before that was enabled. – iiz Commented Nov 4, 2013 at 3:54
- 2 Are those the only three notices? My hunch is that your database is dropping out, but that would usually trigger its own notice. – Matthew Boynes Commented Nov 8, 2013 at 15:08
- I get only these three notices exactly when this error occurs. It happens between 2-3 times an hour and I can see no pattern in its timing. It can happen when trying to access any page not just home/archives. The level of PHP loggin is set to 32767 [E_ALL]. I think I previously tried WP_DEBUG and saw nothing but can't be sure. Now the site in question is live [! no option on this]. But I can do another hidden install with the same parameters as this if you think that would be worth it. – iiz Commented Nov 8, 2013 at 20:01
- 1 Can you look in the access logs at the same time to find out what request is triggering it? – jezmck Commented Nov 12, 2013 at 22:02
2 Answers
Reset to default 1There are two types of 404 errors: WordPress-generated, and server-generated.
In some server environments, 404s could be inaccurately displayed by the server in cases of CPU overload or due to certain instances of misconfiguration, etc. Usually server-generated 404 errors will say something like "Nginx" or "Apache" at the bottom of the page (depends on server type).
In other situations, "false positive" 404 errors could be generated by WordPress (PHP) because security plugins are blocking access to loaded resources:
Why am I sometimes getting a 404 error when I try to update a page with Elementor?
https://wordpress/support/topic/getting-false-positive-404-errors-with-newest-update/
Try disabling any security plugins, clear caches, and refresh the page. Security modules such as ModSecurity installed on your server could also potentially be the cause.
It could also be caused by a poorly coded theme or plugin. Check if there's a common theme or plugin installed on all the sites involved. And if this issue only occurs on Media Temple hosting, it's possible they have something misconfigured, or even that your server is under too much load...
You have not enough information to solve your problem. Try to add full stack trace and request information to your error log to investigate an issue.
You can create your own custom error handler to add stack trace and request information to your error log.
set_error_handler('wpse_120959_handle_error');
function wpse_120959_handle_error( $errno, $errstr, $errfile, $errline ) {
if( $errno === E_USER_NOTICE ) {
$error = PHP_EOL . PHP_EOL;
$error .= sprintf('You have an error notice: "%s" in file "%s" at line: "%s".', $errstr, $errfile, $errline);
$error .= wpse_120959_generate_stack_trace() . PHP_EOL;
$error .= 'Request information:' . PHP_EOL;
$error .= wpse_120959_generate_http_request_info();
error_log( $error );
}
}
// Function from php http://php/manual/en/function.debug-backtrace.php#112238
function wpse_120959_generate_stack_trace() {
$e = new \Exception();
$trace = explode( "\n" , $e->getTraceAsString() );
// reverse array to make steps line up chronologically
$trace = array_reverse( $trace );
array_shift( $trace ); // remove {main}
array_pop( $trace ); // remove call to this method
$length = count( $trace );
$result = array();
for ($i = 0; $i < $length; $i++) {
$result[] = ($i + 1) . ')' . substr( $trace[$i], strpos( $trace[$i], ' ' ) ); // replace '#someNum' with '$i)', set the right ordering
}
$result = implode("\n", $result);
$result = "\n" . $result . "\n";
return $result;
}
function wpse_120959_generate_http_request_info() {
$request_info = '';
$request_info_format = "%s %s %s\nHTTP headers:\n";
$headers = wpse_120959_get_headers();
$header_format = "%s: %s \n";
$request_method = filter_input( INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_STRING );
$request_uri = filter_input( INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_STRING );
$server_protocol = filter_input( INPUT_SERVER, 'SERVER_PROTOCOL', FILTER_SANITIZE_STRING );
$request_info = sprintf( $request_info_format, $request_method, $request_uri, $server_protocol );
foreach ( $headers as $name => $value ) {
$request_info .= sprintf( $header_format, $name, $value );
}
return $request_info;
}
function wpse_120959_get_headers() {
$headers = [];
foreach ($_SERVER as $name => $value) {
if (preg_match('/^HTTP_/', $name ) ) {
$value = filter_input( INPUT_SERVER, $name, FILTER_SANITIZE_STRING );
$name = strtr( substr( $name, 5 ), '_', ' ');
$name = ucwords( strtolower( $name ) );
$name = strtr( $name, ' ', '-' );
// add to list
$headers[$name] = $value;
}
}
return $headers;
}
You can check if this is working by adding trigger_error somewhere in your code e.g in single.php
file.
trigger_error('Annoying notice');
Your error log should output something like that:
2018/07/02 14:26:00 [error] 714#714: *58 FastCGI sent in stderr: "PHP message:
You have an error notice: "Annoying notice" in file "/var/www/test/content/themes/twentyseventeen/single.php" at line: "19".
1) /var/www/test/index.php(17): require('/var/www/test/w...')
2) /var/www/test/wordpress/wp-blog-header.php(19): require_once('/var/www/test/w...')
3) /var/www/test/wordpress/wp-includes/template-loader.php(74): include('/var/www/test/c...')
4) /var/www/test/content/themes/twentyseventeen/single.php(19): trigger_error('Annoying notice')
5) [internal function]: wpse_120959_handle_error(1024, 'Annoying notice', '/var/www/test/c...', 19, Array)
Request information:
GET /hello-world/ HTTP/1.1
HTTP headers:
Accept-Language: en-US;q=0.8,en;q=0.7
Accept-Encoding: gzip, deflate
Referer: http://test.local/
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
User-Agent: Mozilla/5.0 AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1
Upgrade-In" while reading upstream, client: 192.168.10.1, server: test.local, request: "GET /hello-world/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock:", host: "test.local", referrer: "http://test.local"
With this kind of message it will be much easier to find out where the problem is.