# Interger ranges between libvirt and PHP

This page address the integer range conflict between PHP and Libvirt. You should read this if you do use functions that could return numbers bigger than 2^31 (i.e. 2GB in case of functions returning bytes).

Problem description: A lot of libvirt functions do return unsigned long long values (64bit unsigned). On the other hand, PHP does use long for all integers. This means that the largest number on 32bit systems is 2147483647. In case of bytes it means only 2GB. What happen when you try to return larger number may vary a lot. It seems that on 64bit platforms PHP can handle 64 bit signed numbers but this is not confirmed.

Because of this many functions will return possibly large numbers as string. As PHP uses implicit type conversion this is not a big issue (and you can disable it via &php.ini; option). You can encounter these basic situations:

1. If you need to output the value, you can safely print the string and there will be no difference

2. If you are sure that the returned number is within the range, you can use it as number and PHP will cast it for you when needed

3. If you are sure that your platform will handle 64bit numbers correctly, you can disable this behaviour via php.ini `libvirt.longlong_to_string` option

4. In all the other cases you can uses gm functions for multiprecision arithmetics. You will probably convert the string to gmp number, divide it and use as number.

   Handling of large numbers using multiprecision library

       <?php
            // suppose that we have number of I/O reads in $reads
           $reads_div_int=gmp_intval(gmp_div($reads,1024)) ;  //note the implicit convertsion from string to gmp_number.
       }
       ?>

   GMP does of course provide more arithmetic operations than division but converting bytes to kilobytes or megabytes is probably the most common operation.

If you are sure that you platform can handle 64bit numbers and you do not want to use conversion to string, you can disable this behaviour in &php.ini; via option `libvirt.longlong_to_string`. By default it is set to 1 (convert long long to string), setting it to 0 will force php-libvirt to return long long as long.