• Resolved svet

    (@sveslavchev)


    Dear developers,

    The latest version (version 2.7.0) of the plugin is showing the following Notice: “Use of undefined constant YASR_FIRST_SETID – assumed ‘YASR_FIRST_SETID’ (this will throw an Error in a future version of PHP)”.

    I have found this notice after the server CPU reached 100% usage. Disabling the plugin solved the CPU usage, the notice is not logged in the logs anymore.

    Please fix the notice, since it leads to higher CPU and IO usage.

    Kind regards
    Svet

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor dudo

    (@dudo)

    Hello, thank you for using YASR.

    This is weird, since the constant should be always defined (unless you manually removed an option from the DB) and even if not, this kind of notice should never be a problem for the CPU.

    To fix this download this file https://gist.github.com/Dudo1985/9a0248c790bf69f751035369d1b8f836 and upload with FTP into wp-content/plugins/yet-another-stars-rating/includes and overwrite the existing one.

    Let me know!

    Best,
    Dario

    Thread Starter svet

    (@sveslavchev)

    Dear @dudo,

    I was talking from my experience, not guessing. After disabling the plugin the CPU load on the VPS dropped several times.

    I saw load on the CPU for the following reasons:

    1. The error should logged in the log file – CPU/IO load
    2. The Sentry monitoring system should processes, prepare and report the error to the Sentry servers
    3. The newrelic php-module also should processes the warning, log the data, the call stack, the context etc. and report it to the server

    Please note that some of the error reporting above (p.2 and p.3) is happening in real-time. This means that several API calls are made in the same request cycle. The API calls themselves require several hundred milliseconds and are “blocking” the child php-fpm process during this time. For this reason a new child php-fpm processes must be spawn to accept the next requests.

    Of course a php Notice/Warning/Error leads to CPU load in any system that has some type of error reporting, which is most hosting providers and most of the managed or self managed VPS servers.

    Please note, that it took minutes the plugin to deplete my monitoring quota on both platforms… Quota, which in normal usage lasts a whole month ??

    The problem:

    From the dump below it is clear that the warning comes from the
    includes/shortcodes/classes/YasrShortcode.php and not from the yasr-includes-init.php. I suppose that the yasr-includes-init.php file is never included/required in this execution path.

    E_WARNING: Use of undefined constant YASR_FIRST_SETID - assumed 'YASR_FIRST_SETID' (this will throw an Error in a future version of PHP)
    in YasrShortcode::__construct called at WEBROOT/wp-content/plugins/yet-another-stars-rating/includes/shortcodes/classes/YasrVisitorVotes.php (35)
    in YasrVisitorVotes::__construct called at WEBROOT/wp-content/plugins/yet-another-stars-rating/includes/shortcodes/yasr-shortcode-functions.php (88)
    in shortcode_visitor_votes_callback called at WEBROOT/wp-includes/shortcodes.php (343)
    in do_shortcode_tag called at ? (?)
    in preg_replace_callback called at WEBROOT/wp-includes/shortcodes.php (218)
    in do_shortcode called at WEBROOT/wp-content/themes/THEME/inc/helpers/helpers-shortcode.php (203)
    in flatsome_contentfix called at WEBROOT/wp-includes/class-wp-hook.php (292)
    in WP_Hook::apply_filters called at WEBROOT/wp-includes/plugin.php (212)
    in apply_filters called at WEBROOT/wp-includes/post-template.php (253)
    in the_content called at WEBROOT/wp-content/themes/CHILD_THEME/template-parts/posts/content-single.php (3)
    in require called at WEBROOT/wp-includes/template.php (732)
    in load_template called at WEBROOT/wp-includes/template.php (676)
    in locate_template called at WEBROOT/wp-includes/general-template.php (204)
    in get_template_part called at WEBROOT/wp-content/themes/THEME/template-parts/posts/single.php (14)
    in require called at WEBROOT/wp-includes/template.php (732)
    in load_template called at WEBROOT/wp-includes/template.php (676)
    in locate_template called at WEBROOT/wp-includes/general-template.php (204)
    in get_template_part called at WEBROOT/wp-content/themes/THEME/template-parts/posts/layout.php (12)
    in require called at WEBROOT/wp-includes/template.php (732)
    in load_template called at WEBROOT/wp-includes/template.php (676)

    I hope this helps to fix the problem.

    Kind regards
    Svet

    Plugin Contributor dudo

    (@dudo)

    1. The error should logged in the log file – CPU/IO load
    2. The Sentry monitoring system should processes, prepare and report the error to the Sentry servers
    3. The newrelic php-module also should processes the warning, log the data, the call stack, the context etc. and report it to the server

    Now I see, thank you.

    From the dump below it is clear that the warning comes from the
    includes/shortcodes/classes/YasrShortcode.php and not from the yasr-includes-init.php. I suppose that the yasr-includes-init.php file is never included/required in this execution path.

    The file yasr-includes-init.php just init anything else that is loaded in both admin and public sides, even the file YasrShortcode.php is loaded there.

    Did you tried to upload the file linked above with ftp?

    • This reply was modified 3 years, 7 months ago by dudo.
    Thread Starter svet

    (@sveslavchev)

    Did you tried to upload the file linked above with ftp?

    Oh, I see. You updated the file by adding the else statement on lines 224,225 :

    diff yasr-includes-init.php.old yasr-includes-init.php.new

    223a224,225
    > } else {
    >     define('YASR_FIRST_SETID', 1);

    Yes, this fixes the problem with the PHP warnings.

    Thanks for the solution! Hoping that I helped too!

    Regards
    Svet

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Use of undefined constant YASR_FIRST_SETID’ is closed to new replies.