OWNet (PHP)

ownet.php


 

Defined constants


   OWNET_DEFAULT_HOST='127.0.0.1'
   OWNET_DEFAULT_PORT=1234
   OWNET_LINK_TYPE_SOCKET=0
   OWNET_LINK_TYPE_STREAM=1

   OWNET_MSG_ERROR=0
   OWNET_MSG_NOP=1
   OWNET_MSG_READ=2
   OWNET_MSG_WRITE=3
   OWNET_MSG_DIR=4
   OWNET_MSG_SIZE=5
   OWNET_MSG_PRESENCE=6
   OWNET_MSG_DIR_ALL=7
   OWNET_MSG_READ_ANY=99999

   TCP_NODELAY=1
   IPPROTO_TCP=6

Global Variables


   OWNET_GLOBAL_CACHE_STRUCTURE (array)

Class OWNet

   all read and set functions can return NULL if an error occur!

   EVERY FUNCTION TRIGGER AN ERROR! you should use @$ow->function to don't handle errors

   OWNet($host='',$timeout=5,$use_swig_dir=true)


       $host
           host name with port OR uri
           scheme://host:port    (see function setHost for more information about scheme)
           scheme://host
           host:port
           host
           anyother will get OWNET_DEFAULT_HOST and OWNET_DEFAULT_PORT
       $timeout
           the timeout when reading sockets and streams
       $use_swig_dir
           when getting dir we can output an array (use_swig_dir=false) or an string with "," separator (use_swig_dir=true)

   setTimeout($timeout=5)


       $timeout
           the timeout when reading sockets and streams

   getTimeout()


       return current timeout setted by setTimeout or OWNet

   setUseSwigDir($use)


       $use
           use_swig_dir sting or array output when reading directory

   getUseSwigDir()


       return current use_swig_dir setted by setUseSwigDir or OWNet

   setHost($host='')


       $host
           host name with port OR uri
           scheme://host:port
           scheme://host
           host:port
           host
           $host will be parsed with parse_url() function
           if no scheme was set in parse_url() array we will add an default scheme "tcp://" and retry parse_url()
           if no host was set in parse_url() we will use OWNET_DEFAULT_HOST host
           if no port was set in parse_url() we will use OWNET_DEFAULT_PORT port
           scheme "stream" and "ow-stream" are special schemes that will force class to use streams functions instead socket functions
           socket functions are faster and use less computer resources, you will need extension socket loaded (with dl("socket.so") or dl("socket.dll") or static compiled)
           socket functions are used if function_exists("socket_connect") return true and scheme != "stream" and !="ow-stream"

   getHost()


       return an $host that can be used with setHost again

   read($path,$parse_value=true)


       $path
           file to read from owserver
       $parse_value
           if true will return an parsed variable (string, bool or double)
           if false will return always string variables

   dir($path)


       $path
           directory to read files
       if use_swig_dir is true will return an string with "," separator
       if use_swig_dir is false will return an array with all files ordered by owserver

   presence($path)


       $path
           file to check presence
       return true or false if presence ok

   get($path='/',$get_type=OWNET_MSG_READ,$return_full_info_array=false,$parse_php_type=true)

       MAIN FUNCTION FOR READ FROM OWSERVER

       $path
           file to read
       $get_type
           OWNET_MSG_* constant for each read function
       $return_full_info_array
           return information (for debugging) about owserver protocol
       $pase_php_type
           return an parsed variable (bool, string or double)
           if false return always string

   set($path,$value='')


       $path
           file to be write
       $value
           value to write
       return true or false on error

Examples




$ow=new OWNet("tcp://172.16.1.100:1234");
print_r($ow->dir("/"));
print_r($ow->read("/10.E8C1C9000800/temperature"));
print_r($ow->presence("/10.E8C1C9000800"));
print_r($ow->set("/10.E8C1C9000800/temphigh",35)); // any value will be converted to string by fwrite function or socket_write

no problems setting ownet class variable to another type, no memory leak present when unsetting without unset() function
$ow=false    or
$ow=NULL    or
$ow=""        or
unset($ow)

Roberto Spadim

Previous page: OWNet (perl)
Next page: libownet (C)