Visualizzazione dei risultati da 1 a 9 su 9
  1. #1

    Problema con apc_fetch()

    Il capitolo 12 di questo libro è scritto davvero molto male in quanto è pieno di errori.
    Ho trovato un nuovo problema al codice numero 5 che consta di 2 file. In genere apro lo script provo a leggerlo e a cercare di indovinare l'output e poi lo lancio.
    Secondo i miei calcoli dovrei leggere questo html:
    codice HTML:
    <h1>\woo\base\MemApplicationRegistry</h1>
    1
    <pre></pre>
    <h1>\woo\base\SessionRegistry</h1>
    1
    <pre></pre>
    mentre in realtà leggo questo:
    codice HTML:
    <html><head></head><body><h1>\woo\base\MemApplicationRegistry</h1><br> <b>Fatal error</b>: Call to undefined function apc_fetch() in <b>C:\xampp\htdocs\9781430260318_Chapter_12_Code\listing12.05.php</b> on line <b>145</b><br> </body></html>
    I 2 file sono questi:
    listing12.05.php
    Codice PHP:
    <?php
    namespace woo\base;
    abstract class 
    Registry {
        abstract protected function 
    get$key );
        abstract protected function 
    set$key$val );
    }
    class 
    RequestRegistry extends Registry {
        private 
    $values = array();
        private static 
    $instance=null;
        private function 
    __construct() {}
        static function 
    instance() {
            if ( 
    is_null(self::$instance) ) { self::$instance = new self(); }
            return 
    self::$instance;
        }
        protected function 
    get$key ) {
            if ( isset( 
    $this->values[$key] ) ) {
                return 
    $this->values[$key];
            }
            return 
    null;
        }
        protected function 
    set$key$val ) {
            
    $this->values[$key] = $val;
        }
        static function 
    getRequest() {
            
    $inst self::instance();
            if ( 
    is_null$inst->get"request" ) ) ) {
                
    $inst->set('request', new \woo\controller\Request() );
            }
            return 
    $inst->get"request" );
        }
    }
    class 
    SessionRegistry extends Registry {
        private static 
    $instance=null;
        private function 
    __construct() {
            
    session_start();
        }
        static function 
    instance() {
            if ( 
    is_null(self::$instance) ) { self::$instance = new self(); }
            return 
    self::$instance;
        }
        protected function 
    get$key ) {
            if ( isset( 
    $_SESSION[__CLASS__][$key] ) ) {
                return 
    $_SESSION[__CLASS__][$key];
            }
            return 
    null;
        }
        protected function 
    set$key$val ) {
            
    $_SESSION[__CLASS__][$key] = $val;
        }
        function 
    setDSN$dsn ) {
            
    self::instance()->set('dsn'$dsn );
        }
        function 
    getDSN( ) {
            return 
    self::instance()->get("dsn");
        }
    }
    class 
    ApplicationRegistry extends Registry {
        private static 
    $instance=null;
        private 
    $freezedir "data";
        private 
    $values = array();
        private 
    $mtimes = array();
        private 
    $request=null;
        private function 
    __construct() { }
        static function 
    clean() {
            
    self::$instance=null;
        }
        static function 
    instance() {
            if ( 
    is_null(self::$instance) ) { self::$instance = new self(); }
            return 
    self::$instance;
        }
        protected function 
    get$key ) {
            
    $path $this->freezedir DIRECTORY_SEPARATOR $key;
            if ( 
    file_exists$path ) ) {
                
    clearstatcache();
                
    $mtime=filemtime$path );
                if ( ! isset(
    $this->mtimes[$key] ) ) { $this->mtimes[$key]=0; }
                if ( 
    $mtime $this->mtimes[$key] ) {
                    
    $data file_get_contents$path );
                    
    $this->mtimes[$key]=$mtime;
                    return (
    $this->values[$key]=unserialize$data ));
                }
            }
            if ( isset( 
    $this->values[$key] ) ) {
                return 
    $this->values[$key];
            }
            return 
    null;
        }
        protected function 
    set$key$val ) {
            
    $this->values[$key] = $val;
            
    $path $this->freezedir DIRECTORY_SEPARATOR $key;
            
    file_put_contents$pathserialize$val ) );
            
    $this->mtimes[$key]=time();
        }
        static function 
    getDSN() {
            return 
    self::instance()->get('dsn');
        }
        static function 
    setDSN$dsn ) {
            return 
    self::instance()->set('dsn'$dsn);
        }
        static function 
    getRequest() {
            
    $inst self::instance();
            if ( 
    is_null$inst->request ) ) {
                
    $inst->request = new \woo\controller\Request();
            }
            return 
    $inst->request;
        }
    }
    class 
    MemApplicationRegistry extends Registry {
        private static 
    $instance=null;
        private 
    $values=array();
        private 
    $id;
        private function 
    __construct() { }
        static function 
    instance() {
            if ( 
    is_null(self::$instance) ) { self::$instance = new self(); }
            return 
    self::$instance;
        }
        protected function 
    get$key ) {
            return \
    apc_fetch$key );
        }
        protected function 
    set$key$val ) {
            return \
    apc_store$key$val );
        }
        static function 
    getDSN() {
            return 
    self::instance()->get("dsn");
        }
        static function 
    setDSN$dsn ) {
            return 
    self::instance()->set("dsn"$dsn);
        }
    }
    ?>
    listing12.05.run.php
    Codice PHP:
    <?php
    // put me in a web facing directory
    // together with listing12.05.php
    // then run in two windows -- confirm that an update in one
    // window is reflected in the other next time it reloads
    require_once( "listing12.05.php" ); // Registry
    print "<h1>\woo\base\MemApplicationRegistry</h1>";
    $reg = \woo\base\MemApplicationRegistry::instance();
    if ( 
    is_null$reg->getDSN() ) ) {
        
    $reg->setDSN(1);
    }
    print 
    $reg->getDSN();
    print 
    "<pre>";
    $reg->setDSN$reg->getDSN()+1);
    print 
    "</pre>";
    print 
    "<h1>\woo\base\SessionRegistry</h1>";
    $reg2 = \woo\base\SessionRegistry::instance();
    if ( 
    is_null$reg2->getDSN() ) ) {
        
    $reg2->setDSN(1);
    }
    print 
    $reg2->getDSN();
    print 
    "<pre>";
    $reg2->setDSN$reg2->getDSN()+1);
    print 
    "</pre>";
    ?>
    Più pratica in futuro...

  2. #2
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Hai installato apc ?
    Cosa dice phpinfo() ;
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

  3. #3
    no come si installa?
    Più pratica in futuro...

  4. #4
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

  5. #5
    Quote Originariamente inviata da badaze Visualizza il messaggio
    A tuo avviso posso sorvolare oppure è importante conoscere anche questo strumento di php? Sto leggendo un libro si pattern di questo linguaggio. Il risultato che ho scritto sopra con apc installato è corretto giusto?
    Più pratica in futuro...

  6. #6
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Non ne ho la minima idea. Per me php è solo un hobby.
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

  7. #7
    Quote Originariamente inviata da badaze Visualizza il messaggio
    Non ne ho la minima idea. Per me php è solo un hobby.
    cosa usi per programmare?
    Più pratica in futuro...

  8. #8
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120
    Lascia perdere apc.
    Prima che ti serva passeranno lustri

  9. #9
    Quote Originariamente inviata da luca200 Visualizza il messaggio
    passeranno lustri
    Ok, meglio! comunque mai sentita questa espressione...
    Più pratica in futuro...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.