Changeset 2661


Ignore:
Timestamp:
Apr 19, 2012, 7:23:21 AM (9 years ago)
Author:
komodo
Message:

oubli commit

File:
1 edited

Legend:

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

    r1540 r2661  
    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() {
    35     if (! $this->semaphore) {
    36       $id = ftok(self::getFileCommands(), 's');
    37       $this->semaphore = sem_get($id);
    38     }
     48#    if (! $this->semaphore) {
     49      $this->semaphore = sem_get(self::getSemId(), 1, 0666, -1);
     50#    }
    3951    sem_acquire($this->semaphore);
    4052  }
     
    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.