Like many Russians, lately I go to vote every day on the site
10russia.ru . If someone does not know, Russia 10 is an all-Russian project, under which everyone can vote for their favorite geographical or architectural object in Russia. The task of the project is the selection of ten new visual symbols of Russia.
I thought the numbers in TOP2 in voting were strange, and I decided to see how they change.
There was little time, and in haste a small parser wrote, which saves once every 2-3 seconds data on the number of votes on the site and SMS. To display this data, I created a website (The design and the basis of the graphics from here were taken from
habrahabr.ru/post/176547 . I hope the author will not mind). I didn’t want to spend money, and only a personal weak VDS was at disposal, which would have quickly gone down if the data were dynamically generated. Therefore, it was decided to do with static html and json file generation by crown. It will be interesting to see how much the VDS can handle without changing the current configuration (CPU 300MHz, RAM 128 Mb), considering that there are two small services and one small website running there. At the end of the vote lay out, if anyone should, all the data obtained by voting.
Parser listing
<?php set_time_limit(0); function handleError($errno, $errstr, $errfile, $errline, array $errcontext) { if (0 === error_reporting()) { return false; } throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } set_error_handler('handleError'); mysql_connect('localhost', 'login', 'password'); mysql_select_db('10russia'); function addNewData($html, $key) { $site = $sms = 0; if( preg_match('/<span id="count_votes_site">([^<]+)/iu', $html, $match) ) { $site = (int)str_replace(' ', '', $match[1]); } if( preg_match('/<span id="count_votes_sms">([^<]+)/iu', $html, $match) ) { $sms = (int)str_replace(' ', '', $match[1]); } if($site && $sms) { $all = $sms + $site; mysql_query("INSERT INTO stat(`key`, sms, site, `all`) VALUES('$key', $sms, $site, $all)"); } } $urls = array( 'object_31' => 'http://10russia.ru/object_31', 'object_61' => 'http://10russia.ru/object_61' ); while(true) { foreach($urls as $key => $url) { try { $result = file_get_contents($url); addNewData($result, $key); sleep(1); } catch(Exception $e) {} } }
Listing script to create json files
<?php mysql_connect('localhost', 'login', 'password'); mysql_select_db('10russia'); $keys = array( 'object_31' => 'object31.json', 'object_61' => 'object61.json' ); foreach($keys as $key => $file) { $filename = dirname(__FILE__) . '/' . $file . '.tmp'; $fLink = fopen($filename, 'w'); if($fLink) { $result = mysql_query("SELECT `date`, `all` FROM stat WHERE `key`='$key' ORDER BY id ASC"); fwrite($fLink, "[\n"); $row = mysql_fetch_assoc($result); $first = true; do { $str = ''; if(!$first){ $str = ","; } else { $first = false; } fwrite($fLink, $str . '['.strtotime($row['date']) . "000,{$row['all']}]" ); } while($row = mysql_fetch_assoc($result)); fwrite($fLink, "]"); fclose($fLink); rename($filename, dirname(__FILE__) . '/' . $file); } }
An interesting point - I first generate a .tmp file, and then overwrite the file generated an hour ago, thereby avoiding the situation when the file does not exist or is not fully generated.
')
Interesting points on the charts
Maximum increase in 30 minutes
The overall dynamics of all time monitoring
VGTRK
I hope that you have not created big problems for you, given the great popularity of the project, I think you were ready for a large flow of visitors. By the way, if someone is looking for a job as a system administrator in Moscow, then the site creators are looking for employees who are no longer quite original, but in a rare way:

Links
See what I did, read the detailed voting statistics and draw conclusions:
http://10russia.miningdata.ru/