https://gist.github.com/nannubest/998242

<?php

/*
* SQLite3 Class
* based on the code of miquelcamps
* @see http://7devs.com/code/view.php?id=67
*/

class DB{
  private $sqlite;
  private $mode;

  function __construct( $filename, $mode = SQLITE3_ASSOC ){
    $this->mode = $mode;
    $this->sqlite = new SQLite3($filename);

  }

  function __destruct(){
    @$this->sqlite->close();
  }

  function clean( $str ){
    return $this->sqlite->escapeString( $str );
  }

  function query( $query ){
    $res = $this->sqlite->query( $query );
    if ( !$res ){
      throw new Exception( $this->sqlite->lastErrorMsg() );
    }

    return $res;
  }

  function queryRow( $query ){
    $res = $this->query( $query );
    $row = $res->fetchArray( $this->mode );
    return $row;
  }

  function queryOne( $query ){
    $res = $this->sqlite->querySingle( $query );
    return $res;
  }

  function queryAll( $query ){
    $rows = array();
    if( $res = $this->query( $query ) ){
      while($row = $res->fetchArray($this->mode)){
        $rows[] = $row;
      }
    }
    return $rows;
  }

  function getLastID(){
    return $this->sqlite->lastInsertRowID();
  }
}

// initialize
$db = new DB( 'database.sqlite' );

// create the database structure
$query = 'CREATE TABLE IF NOT EXISTS "foobar" (
            "id" INTEGER PRIMARY KEY AUTOINCREMENT,
            "name" TEXT
          );';
$db->query( $query );

// insert some data to the database
$query = array(
  "INSERT INTO foobar VALUES(1,'LOLOLOL');",
  "INSERT INTO foobar VALUES(2,'Lorem Ipsum....');"
  );

foreach($query as $key):
  $db->query( $key );
endforeach;

// query example, multiple rows
$users = $db->queryAll( "SELECT * FROM foobar" );

// query example, one row
$search = 'Lorem Ipsum....';
$user_info = $db->queryRow( sprintf( "SELECT * FROM foobar WHERE name = '%s'", $db->clean( $search ) ) );

// query example, one result
$total_users = $db->queryOne( "SELECT COUNT(*) FROM foobar" );

// insert query
$insert = array(
  'id' => 3,
  'text' => 'Testing'
);
$db->query( sprintf( "INSERT INTO foobar VALUES ( %s, '%s' )", $db->clean ( $insert['id'] ), $db->clean( $insert['text'] ) ) );

?>

sudo lsof -nP -i 

On macOS High Sierra and later, use this command:

sudo lsof -nP -iTCP:$PORT | grep LISTEN

or to just see just IPv4:

sudo lsof -nP -i4TCP:$PORT | grep LISTEN

On older versions, use one of the following forms:

sudo lsof -nP -iTCP:$PORT | grep LISTEN
sudo lsof -nP -i:$PORT | grep LISTEN

说明:WebTorrent是一款可以直接在线播放视频的BT下载客户端,而webtorrent-cli是它的命令行应用程序。

1,安装Nodejs

Debian/Ubuntu系统
apt-get install -y nodejs nodejs-dev node-gyp libssl1.0-dev

Centos系统
yum install nodejs nodejs-dev node-gyp libssl1.0-dev -y

2, 安装webtorrent-cli

npm install webtorrent-cli -g

使用

以下路径分别为磁力链接、种子HTTP链接地址、服务器种子路径,种子HASH

webtorrent magnet:?xt=urn:btih:828E2289E73ED9C96C16203E24EBD66E198EB65F
webtorrent http://moerats.com/debian-9.2.torrent
webtorrent /root/debian-9.2.torrent
webtorrent 828E2289E73ED9C96C16203E24EBD66E198EB65F

常用参数

#了解更多参数输入webtorrent --help即可
-o, --out [path]  #设置BT下载目录,默认为当前目录
-p, --port [number]  #设置HTTP服务器端口,默认8000