<commit_before><?php
//das ist notwendig damit cli scripte was mit dem apc cache machen können
//direkt in der cli ist das leider nicht möglich, da der speicher im webserver liegt
class Kwf_Util_Apc
{
    public static function getHttpPassword()
    {
        $file = 'cache/apcutilspass';
        if (!file_exists($file)) {
            file_put_contents($file, time().rand(100000, 1000000));
        }
        return file_get_contents($file);
    }

    public static function callClearCacheByCli($params)
    {
        $config = Kwf_Registry::get('config');
        $d = $config->server->domain;
        if (!$d && file_exists('cache/lastdomain')) {
            //this file gets written in Kwf_Setup to make it "just work"
            $d = file_get_contents('cache/lastdomain');
        }
        $s = microtime(true);
        $pwd = Kwf_Util_Apc::getHttpPassword();
        $urlPart = "http".($config->server->https?'s':'')."://apcutils:".Kwf_Util_Apc::getHttpPassword()."@";
        $url = "$urlPart$d/kwf/util/apc/clear-cache";

        $client = new Zend_Http_Client();
        $client->setMethod(Zend_Http_Client::POST);
        $client->setParameterPost($params);
        $client->setConfig(array(
            'timeout' => 60,
            'keepalive' => true
        ));

        $client->setUri($url);
        $response = $client->request();
        $result = !$response->isError() && substr($response->getBody(), 0, 2) == 'OK';
        if (!$result && $config->server->noRedirectPattern) {
            $d = str_replace(array('^', '\\', '$'), '', $config->server->noRedirectPattern);
            $url2 = "$urlPart$d/kwf/util/apc/clear-cache";
            $client->setUri($url2);
            $response = $client->request();
        }
        return array(
            'result' => $result,
            'message' => $response->getBody(),
            'time' => round((microtime(true)-$s)*1000),
            'url' => $url,
            'url2' => isset($url2) ? $url2 : null,
            'params' => $params
        );
    }

    public static function dispatchUtils()
    {
        if (empty($_SERVER['PHP_AUTH_USER']) ||
            empty($_SERVER['PHP_AUTH_PW']) ||
            $_SERVER['PHP_AUTH_USER']!='apcutils' ||
            $_SERVER['PHP_AUTH_PW']!=self::getHttpPassword())
        {
            header('WWW-Authenticate: Basic realm="APC Utils"');
            throw new Kwf_Exception_AccessDenied();
        }

        if (substr($_SERVER['REQUEST_URI'], 0, 25) == '/kwf/util/apc/clear-cache') {
            $s = microtime(true);
            if (isset($_REQUEST['cacheIds'])) {
                foreach (explode(',', $_REQUEST['cacheIds']) as $cacheId) {
                    apc_delete($cacheId);
                }
            } else if (isset($_REQUEST['files'])) {
                foreach (explode(',', $_REQUEST['files']) as $file) {
                    @apc_delete_file($file);
                }
            } else if ($_REQUEST['type'] == 'user') {
                apc_clear_cache('user');
            } else {
                apc_clear_cache('file');
            }
            echo 'OK '.round((microtime(true)-$s)*1000).' ms';
            exit;
        } else if ($_SERVER['REQUEST_URI'] == '/kwf/util/apc/get-counter-value') {
            $prefix = Kwf_Cache::getUniquePrefix().'bench-';
            echo apc_fetch($prefix.$this->_getParam('name'));
            exit;
        } else if ($_SERVER['REQUEST_URI'] == '/kwf/util/apc/stats') {
            self::stats();
        } else if ($_SERVER['REQUEST_URI'] == '/kwf/util/apc/iterate') {<commit_msg>fix clearing apc cache<commit_after><?php
//das ist notwendig damit cli scripte was mit dem apc cache machen können
//direkt in der cli ist das leider nicht möglich, da der speicher im webserver liegt
class Kwf_Util_Apc
{
    public static function getHttpPassword()
    {
        $file = 'cache/apcutilspass';
        if (!file_exists($file)) {
            file_put_contents($file, time().rand(100000, 1000000));
        }
        return file_get_contents($file);
    }

    public static function callClearCacheByCli($params)
    {
        $config = Kwf_Registry::get('config');
        $d = $config->server->domain;
        if (!$d && file_exists('cache/lastdomain')) {
            //this file gets written in Kwf_Setup to make it "just work"
            $d = file_get_contents('cache/lastdomain');
        }
        $s = microtime(true);
        $pwd = <PASSWORD>();
        $urlPart = "http".($config->server->https?'s':'')."://apcutils:".Kwf_Util_Apc::getHttpPassword()."@";
        $url = "$urlPart$d/kwf/util/apc/clear-cache";

        $client = new Zend_Http_Client();
        $client->setMethod(Zend_Http_Client::POST);
        $client->setParameterPost($params);
        $client->setConfig(array(
            'timeout' => 60,
            'keepalive' => true
        ));

        $client->setUri($url);
        $response = $client->request();
        $result = !$response->isError() && substr($response->getBody(), 0, 2) == 'OK';
        if (!$result && $config->server->noRedirectPattern) {
            $d = str_replace(array('^', '\\', '$'), '', $config->server->noRedirectPattern);
            $url2 = "$urlPart$d/kwf/util/apc/clear-cache";
            $client->setUri($url2);
            $response = $client->request();
        }
        return array(
            'result' => $result,
            'message' => $response->getBody(),
            'time' => round((microtime(true)-$s)*1000),
            'url' => $url,
            'url2' => isset($url2) ? $url2 : null,
            'params' => $params
        );
    }

    public static function dispatchUtils()
    {
        if (empty($_SERVER['PHP_AUTH_USER']) ||
            empty($_SERVER['PHP_AUTH_PW']) ||
            $_SERVER['PHP_AUTH_USER']!='apcutils' ||
            $_SERVER['PHP_AUTH_PW']!=self::getHttpPassword())
        {
            header('WWW-Authenticate: Basic realm="APC Utils"');
            throw new Kwf_Exception_AccessDenied();
        }

        if (substr($_SERVER['REQUEST_URI'], 0, 25) == '/kwf/util/apc/clear-cache') {
            $s = microtime(true);
            if (isset($_REQUEST['cacheIds'])) {
                foreach (explode(',', $_REQUEST['cacheIds']) as $cacheId) {
                    apc_delete($cacheId);
                }
            } else if (isset($_REQUEST['files'])) {
                foreach (explode(',', $_REQUEST['files']) as $file) {
                    @apc_delete_file($file);
                }
            } else if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'user') {
                apc_clear_cache('user');
            } else {
                apc_clear_cache('file');
            }
            echo 'OK '.round((microtime(true)-$s)*1000).' ms';
            exit;
        } else if ($_SERVER['REQUEST_URI'] == '/kwf/util/apc/get-counter-value') {
            $prefix = Kwf_Cache::getUniquePrefix().'bench-';
            echo apc_fetch($prefix.$this->_getParam('name'));
            exit;
        } else if ($_SERVER['REQUEST_URI'] == '/kwf/util/apc/stats') {
            self::stats();
        } else if ($_SERVER['REQUEST_URI'] == '/kwf/util/apc/iterate') {
{'fraction_non_alphanumeric': 0.1750488963397597, 'fraction_numerical': 0.009220452640402346, 'mean_word_length': 2.1153176675369885, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3777217', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2155, 'n_words': 388}