PHP code example of muammertopcu / php-onvif

1. Go to this page and download the library: Download muammertopcu/php-onvif library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

muammertopcu / php-onvif example snippets




f = new Ponvif();
$result = $onvif->discover();

var_dump($result);

array (size=2)
  0 => 
    array (size=6)
      'EndpointReference' => 
        array (size=1)
          'Address' => string 'urn:uuid:2925be82-4d50-11b4-82c8-c42f905c18f8' (length=45)
      'Types' => string 'dn:NetworkVideoTransmitter tds:Device' (length=37)
      'Scopes' => string 'onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/hardware/RVi-IPC11S onvif://www.onvif.org/name/RVi-IPC11S onvif://www.onvif.org/location/' (length=233)
      'XAddrs' => string 'http://192.168.1.205/onvif/device_service http://[fe80::c62f:90ff:fe5c:18f8]/onvif/device_service' (length=97)
      'MetadataVersion' => string '10' (length=2)
      'IPAddr' => string '192.168.1.205' (length=13)
  1 => 
    array (size=6)
      'EndpointReference' => 
        array (size=1)
          'Address' => string 'uuid:2e15cbab-9b44-4074-836d-0bccd8632b3f' (length=41)
      'Types' => string 'dn:NetworkVideoTransmitter' (length=26)
      'Scopes' => string 'onvif://www.onvif.org/location/country/Russia onvif://www.onvif.org/name/RVi onvif://www.onvif.org/hardware/RVi-IPC33M onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/type/Network_Video_Transmitter onvif://www.onvif.org/extension/unique_identifier' (length=261)
      'XAddrs' => string 'http://192.168.1.201/onvif/device_service' (length=41)
      'MetadataVersion' => string '1' (length=1)
      'IPAddr' => string '192.168.1.201' (length=13)



f = new Ponvif();
$onvif->setUsername('admin');
$onvif->setPassword('password');
$onvif->setIPAddress('192.168.1.108');

// In some cases you need to set MediaUrl manually. You can find it in "XAddrs" key (see above).
// $onvif->setMediaUri('http://192.168.1.108:3388/onvif/device_service');

try
{
	$onvif->initialize();
	
	$sources = $onvif->getSources();
	$profileToken = $sources[0][0]['profiletoken'];
	$mediaUri = $onvif->media_GetStreamUri($profileToken);
	
	var_dump($mediaUri);
}
catch(Exception $e)
{
	
}