get_count.php 750 Bytes
Newer Older
Clément Stenac's avatar
Clément Stenac committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
<?php
    require '/home/videolan/etc/db.php';

    /* Open the current */
    $lines = file( "/var/www/local/www.videolan.org/counter.data" );

    if( $lines == FALSE )
    {
        $old = "0 0\n";
    }
    else
    {
        $old = $lines[1];
    }
    
    /* Retrieve new data */ 
    $connect = pg_connect( $connect_string );
    if( !$connect )
    {
	die;
    }
    
    $request = pg_query($connect, "SELECT sum(number) FROM mirrors WHERE file like '%0.8.5%'" );
    if( $row = pg_fetch_array($request) )
    {
        $new = date( "U" )." ".$row[0]."\n";
    }
    pg_close($connect);

    /* Write data */
    $file = fopen( "/var/www/local/www.videolan.org/counter.data", "w" );
    fwrite( $file, $old );
    fwrite( $file, $new );
?>