• This plugin did not work for me, and took a while to debug what was going on.
    [It would be useful if the code reported errors at all the points when it does not embed the photo – all the if statements should have else parts that error_log, for example…]

    I am not sure why the preg_match('#(<head>.+?</head>)#s', $response['body'], $match); in function gphotos_html_get fails on my system.
    But since there is no need there to use a regex, simple string search will be faster, and it makes the plugin work:

                $head_pos_0 = strpos($response['body'], '<head>'); // starting character position
                $head_pos_n = strpos($response['body'], '</head>') + 6; // ending character position
                if($head_pos_0 !== FALSE && $head_pos_n !== FALSE){
                    $head = substr($response['body'], $head_pos_0, $head_pos_n - $head_pos_0 + 1);

    and then use $headinstead of $match[1]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author enomoto celtislab

    (@enomoto-celtislab)

    Thank you for the report.

    I am concerned about the reason that preg_match becomes an error.
    Is it an error in WordPress recommended environment

      PHP 7 or greater
      MySQL 5.6 or greater OR MariaDB 10.0 or greater

    Or is it due to legacy things like PHP version 5.2?

    Thread Starter bwooster47

    (@bwooster47)

    PHP 7.0.18-0ubuntu0.16.04.1 (cli) ( NTS )
    mysql Ver 14.14 Distrib 5.7.19

    I think there is some problem related to size of the matched string.
    [26-Jul-2017 04:12:45 UTC] response len: 665969
    [26-Jul-2017 04:12:45 UTC] strpos <head>: 41
    [26-Jul-2017 04:12:45 UTC] strpos </head>: 614639

    So, length of matched string <head>…</head> is 614639 – 41 + 1 + 6 = 614605
    which is the key thing I think is causing wordpress / apache2 php to return FALSE for the preg_match.

    If the length < 500k, it works fine.

    So, while this may be fixable by changing some PHP limit under Apache, may be better to just avoid trying to preg_match such a large substring.

    Plugin Author enomoto celtislab

    (@enomoto-celtislab)

    Thanks for the detailed report

    The preg_ function such as preg_match is set in php.ini

    Pcre.backtrack_limit
    Pcre.recursion_limit

    If it exceeds the upper limit of the memory size, it seems to be an error.

    Therefore, when large size is expected, it is necessary to process in other way avoiding preg_match, so replace it with the method using strpos, substr as advised and update soon.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Use strpos instead of preg_match?’ is closed to new replies.