コード例 #1
0
 /**
  * start a client.
  */
 function _start()
 {
     global $cfg;
     if ($this->state != CLIENTHANDLER_STATE_READY) {
         $this->state = CLIENTHANDLER_STATE_ERROR;
         array_push($this->messages, "Error. ClientHandler in wrong state on start-request.");
         // write error to stat
         $sf = new StatFile($this->transfer, $this->owner);
         $sf->time_left = 'Error';
         $sf->write();
         // return
         return;
     }
     // Save transfer settings
     $this->settingsSave();
     // flush session-cache (trigger transfers-cache-set on next page-load)
     cacheFlush($cfg['user']);
     // write the session to close so older version of PHP will not hang
     @session_write_close();
     // sf
     $sf = new StatFile($this->transfer, $this->owner);
     // queue or start ?
     if ($this->queue) {
         // queue
         if (FluxdQmgr::isRunning()) {
             // write stat-file
             $sf->queue();
             // send command
             FluxdQmgr::enqueueTransfer($this->transfer, $cfg['user']);
             // log
             AuditAction($cfg["constants"]["queued_transfer"], $this->transfer);
             $this->logMessage("transfer enqueued : " . $this->transfer . "\n", true);
         } else {
             $msg = "queue-request (" . $this->transfer . "/" . $cfg['user'] . ") but Qmgr not active";
             array_push($this->messages, $msg);
             AuditAction($cfg["constants"]["error"], $msg);
             $this->logMessage($msg . "\n", true);
         }
         // set flag
         $this->running = 0;
     } else {
         // start
         // write stat-file
         $sf->start();
         // log the command
         $this->logMessage("executing command : \n" . $this->command . "\n", true);
         // startup
         $this->callResult = exec($this->command);
         AuditAction($cfg["constants"]["start_torrent"], $this->transfer);
         // set flag
         $this->running = 1;
         // wait until transfer is up
         waitForTransfer($this->transfer, true, 20);
     }
     if (empty($this->messages)) {
         // set state
         $this->state = CLIENTHANDLER_STATE_OK;
     } else {
         // error
         $this->state = CLIENTHANDLER_STATE_ERROR;
         $msg = "error starting client. messages :\n";
         $msg .= implode("\n", $this->messages);
         $this->logMessage($msg . "\n", true);
         // write error to stat
         $sf->time_left = 'Error';
         $sf->write();
     }
 }