downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Fonctions de rappel sur clé absente> <Fonctions de rappel
Last updated: Fri, 14 Aug 2009

view this page in

Fonctions de rappel de résultats

Les fonctions de rappel de résultats (type callback) sont appelées par les fonctions Memcached::getDelayed ou Memcached::getDelayedBykey, pour chaque élément du jeu de résultat. Les fonctions de rappel reçoivent un objet Memcached et un tableau avec les informations sur l'élément. La fonction de rappel n'a pas besoin de retourner quoi que ce soit.

Exemple #1 Exemple de fonction de rappel de résultats

<?php
$m 
= new Memcached();
$m->addServer('localhost'11211);
$items = array(
    
'key1' => 'value1',
    
'key2' => 'value2',
    
'key3' => 'value3'
);
$m->setMulti($items);
$m->getDelayed(array('key1''key3'), true'result_cb');

function 
result_cb($memc$item)
{
    
var_dump($item);
}
?>

L'exemple ci-dessus va afficher quelque chose de similaire à :

array(3) {
  ["key"]=>
  string(4) "key1"
  ["value"]=>
  string(6) "value1"
  ["cas"]=>
  float(49)
}
array(3) {
  ["key"]=>
  string(4) "key3"
  ["value"]=>
  string(6) "value3"
  ["cas"]=>
  float(50)
}


add a note add a note User Contributed Notes
Fonctions de rappel de résultats
edwarddrapkin at gmail dot com
12-Mar-2009 01:54
I was having trouble making method calls with the result callbacks in getDelayed, so I emailed the developer.

If you want to use a non-static method as a callback, use the following format: array($obj, 'method'); for example:

<?php
class foo {
    private
$M = false;
   
    public function
__construct() {
       
$this->M = new Memcached();
       
$this->M->addServer('localhost', 11211);       
       
$this->M->set('a', 'test');
    }

    public function
test() {
       
$this->M->getDelayed(array('a'), false, array($this, 'fun'));
    }
   
    public function
fun() {
        echo
"Great Success!";
    }
}

$f = new foo();
$f->test();
?>

or, alternatively:

<?php
class foo {
    public
$M = false;
   
    public function
__construct() {
       
$this->M = new Memcached();
       
$this->M->addServer('localhost', 11211);       
       
$this->M->set('a', 'test');
    }
   
    public function
fun() {
        echo
"Great Success!";
    }
}

$f = new foo();
$f->M->getDelayed(array('a'), false, array($f, 'fun'));
?>

Works great, thanks Andrei :)

Fonctions de rappel sur clé absente> <Fonctions de rappel
Last updated: Fri, 14 Aug 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites