Changeset 2644 for cpc/trunk/project


Ignore:
Timestamp:
Feb 19, 2012, 11:16:59 PM (9 years ago)
Author:
teymour
Message:

Evite le problème du sémaphore basé sur un ID non stable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpc/trunk/project/lib/model/solr/SolrCommands.class.php

    r1540 r2644  
    2525
    2626  private function __construct() {
     27    $this->semaphore = null;
    2728  }
    2829
    2930  public function __destruct() {
    30     if ($this->semaphore)
    31       $this->unprotect();
     31    if ($this->semaphore) {
     32      sem_remove($this->semaphore);
     33      $this->semaphore = null;
     34    }
     35  }
     36
     37  private static function getSemId() {
     38    self::getFileCommands();
     39    $semfile = sfConfig::get('sf_log_dir')."/solr/SolrSem.id";
     40    if (!file_exists($semfile)) {
     41      touch($semfile);
     42    }
     43    $id = ftok($semfile, 's');
     44    return $id;
    3245  }
    3346
    3447  private function protect() {
    3548    if (! $this->semaphore) {
    36       $id = ftok(self::getFileCommands(), 's');
    37       $this->semaphore = sem_get($id);
     49      $this->semaphore = sem_get(self::getSemId());
    3850    }
    39     sem_acquire($this->semaphore);
     51    sem_acquire($this->semaphore, 1);
    4052  }
    4153
    4254  private function unprotect() {
    4355    sem_release($this->semaphore);
    44     sem_remove($this->semaphore);
    45     $this->semaphore = null;
    4656  }
    4757
     
    5363    $str = $status.' : '.json_encode($json)."\n";
    5464    fwrite($this->file, $str, strlen($str));
     65    fclose($this->file);
     66    $this->file = null;
    5567    $this->unprotect();
    5668  }
Note: See TracChangeset for help on using the changeset viewer.