github.com/artpar/rclone@v1.67.3/librclone/php/rclone.php (about)

     1  <?php
     2  /*
     3  PHP interface to librclone.so, using FFI ( Foreign Function Interface )
     4  
     5  Create an rclone object
     6  
     7  $rc = new Rclone( __DIR__ . '/librclone.so' );
     8  
     9  Then call rpc calls on it
    10  
    11      $rc->rpc( "config/listremotes", "{}" );
    12  
    13  When finished, close it
    14  
    15      $rc->close();
    16  */
    17  
    18  class Rclone {
    19  
    20      protected $rclone;
    21      private $out;
    22  
    23      public function __construct( $libshared )
    24      {
    25          $this->rclone = \FFI::cdef("
    26          struct RcloneRPCResult {
    27              char* Output;
    28              int	Status;
    29          };        
    30          extern void RcloneInitialize();
    31          extern void RcloneFinalize();
    32          extern struct RcloneRPCResult RcloneRPC(char* method, char* input);
    33          extern void RcloneFreeString(char* str);
    34          ", $libshared);
    35          $this->rclone->RcloneInitialize();
    36      }
    37  
    38      public function rpc( $method, $input ): array
    39      {
    40          $this->out = $this->rclone->RcloneRPC( $method, $input );
    41          $response = [
    42              'output' => \FFI::string( $this->out->Output ),
    43              'status' => $this->out->Status
    44          ];
    45          $this->rclone->RcloneFreeString( $this->out->Output );
    46          return $response;
    47      }
    48  
    49      public function close( ): void
    50      {
    51          $this->rclone->RcloneFinalize();
    52      }
    53  }