S
S
sparksounds2012-12-14 14:45:49
PHP
sparksounds, 2012-12-14 14:45:49

Calling a specific function on php 5.2.17 under OS X gives an empty response to the browser. Why?

The function is like this:

function strip_nonUtf8($str) {
    static $fourbytes = '[\n\t\r\x20-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]';

    $result = '';
    while (strlen($str) > 2000) {
        if (!preg_match("/^($fourbytes){100}/", $str, $match)) {
            if (preg_match("/^($fourbytes)*/", $str, $match)) {
                $result .= $match[0];
                $str = substr($str, strlen($match[0]));
            }
            // now the first character is bad
            $str = substr($str, 1);
            continue;
        }
        $result .= $match[0];
        $str = substr($str, strlen($match[0]));
    }
    if ($str != '' && preg_match_all("/($fourbytes)+/", $str, $matches, PREG_PATTERN_ORDER)) {
        $result .= join('', $matches[0]);
    }
    $result = strip_tags($result);
    return $result;
}

The error is (Chrome):
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
Apparently the function interrupts the execution of the script.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Melkij, 2012-12-14
@sparksounds

bugs.php.net/bug.php?id=52818
bugs.php.net/bug.php?id=45735

E
Evgeny Elizarov, 2012-12-14
@KorP

Googled? The first link leads here

S
sparksounds, 2012-12-14
@sparksounds

This is not a browser issue. I gave the Chrome error as an example of an empty response from a web server.

K
keltanas, 2012-12-14
@keltanas

Have you tried running this code on 5.3.19 or 5.4.9?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question