| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | $key_space = 'png'; |
|---|
| 4 | $column_family = 'png'; |
|---|
| 5 | $column_family_date = 'date'; |
|---|
| 6 | |
|---|
| 7 | $graph_base_dir="./png/"; |
|---|
| 8 | |
|---|
| 9 | require_once 'Cassandra.php'; |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | // list of seed servers to randomly connect to |
|---|
| 13 | // all the parameters are optional and default to given values |
|---|
| 14 | $servers = array( |
|---|
| 15 | array( |
|---|
| 16 | 'host' => '127.0.0.1', |
|---|
| 17 | 'port' => 9160, |
|---|
| 18 | 'use-framed-transport' => true, |
|---|
| 19 | 'send-timeout-ms' => 1000, |
|---|
| 20 | 'receive-timeout-ms' => 1000 |
|---|
| 21 | ) |
|---|
| 22 | ); |
|---|
| 23 | |
|---|
| 24 | $cassandra = Cassandra::createInstance($servers); |
|---|
| 25 | $cassandra->useKeyspace($key_space); |
|---|
| 26 | $cassandra->setMaxCallRetries(5); |
|---|
| 27 | |
|---|
| 28 | /* |
|---|
| 29 | $cassandra->createStandardColumnFamily( |
|---|
| 30 | $key_space, // keyspace name |
|---|
| 31 | $column_family, // the column-family name |
|---|
| 32 | array( // list of columns with metadata |
|---|
| 33 | array( |
|---|
| 34 | 'name' => 'name', |
|---|
| 35 | 'type' => Cassandra::TYPE_UTF8, |
|---|
| 36 | 'index-type' => Cassandra::INDEX_KEYS, // create secondary index |
|---|
| 37 | 'index-name' => 'NameIdx' |
|---|
| 38 | ), |
|---|
| 39 | array( |
|---|
| 40 | 'name' => 'content', |
|---|
| 41 | 'type' => Cassandra::TYPE_BYTES, |
|---|
| 42 | ), |
|---|
| 43 | array( |
|---|
| 44 | 'name' => 'type', |
|---|
| 45 | 'type' => Cassandra::TYPE_UTF8, |
|---|
| 46 | ), |
|---|
| 47 | array( |
|---|
| 48 | 'name' => 'date', |
|---|
| 49 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 50 | 'index-type' => Cassandra::INDEX_KEYS, |
|---|
| 51 | 'index-name' => 'DateIdx' |
|---|
| 52 | ), |
|---|
| 53 | array( |
|---|
| 54 | 'name' => 'hour', |
|---|
| 55 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 56 | 'index-type' => Cassandra::INDEX_KEYS, |
|---|
| 57 | 'index-name' => 'HourIdx' |
|---|
| 58 | ) |
|---|
| 59 | ) |
|---|
| 60 | // actually accepts more parameters with reasonable defaults |
|---|
| 61 | ); |
|---|
| 62 | */ |
|---|
| 63 | |
|---|
| 64 | $od_graph_base=opendir($graph_base_dir); |
|---|
| 65 | while ($date_dir=readdir($od_graph_base)) |
|---|
| 66 | { |
|---|
| 67 | if ($date_dir != "." && $date_dir != "..") { |
|---|
| 68 | $data_date = $date_dir; |
|---|
| 69 | $tmp=$graph_base_dir.$date_dir; |
|---|
| 70 | if(is_dir($tmp)){ |
|---|
| 71 | // echo $tmp."<br>"; |
|---|
| 72 | $arr_dir_list[]=$tmp; |
|---|
| 73 | $od_file=opendir($tmp); |
|---|
| 74 | while ($file_name=readdir($od_file)) |
|---|
| 75 | { |
|---|
| 76 | $file_full_path = $tmp."/".$file_name; |
|---|
| 77 | if(is_file($file_full_path)){ |
|---|
| 78 | $data_hr= substr($file_name,9,2); |
|---|
| 79 | $data_name=$data_date.$data_hr; |
|---|
| 80 | $data_type=substr($file_name,-3,3); |
|---|
| 81 | $data_content=file_get_contents($file_full_path); |
|---|
| 82 | echo $file_full_path."=>"; |
|---|
| 83 | echo " ,name=".$data_name; |
|---|
| 84 | echo " ,date=".$data_date; |
|---|
| 85 | echo " ,hour=".$data_hr; |
|---|
| 86 | echo " ,type=".$data_type; |
|---|
| 87 | echo "<br>"; |
|---|
| 88 | echo cass_insert($data_name,$data_content,$data_date,$data_hr,$data_type); |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | closedir ($od_graph_base); |
|---|
| 95 | closedir ($od_file); |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | //$target = $cassandra->get($id); |
|---|
| 99 | //echo "content :".$target["name"].": <pre>".print_r($target, true).'</pre><hr/>'; |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | function cass_insert($name,$content,$date,$hour,$type){ |
|---|
| 103 | global $cassandra, $column_family, $column_family_date, $key_space ; |
|---|
| 104 | $ret_png= $cassandra->cf($column_family)->set( |
|---|
| 105 | $name, |
|---|
| 106 | array( |
|---|
| 107 | 'name' => $name, |
|---|
| 108 | 'content' => $content, |
|---|
| 109 | 'date' => $date, |
|---|
| 110 | 'hour' => $hour, |
|---|
| 111 | 'type' => $type |
|---|
| 112 | ) |
|---|
| 113 | ); |
|---|
| 114 | $ret_date= $cassandra->cf($column_family_date)->set( |
|---|
| 115 | $date, |
|---|
| 116 | array( |
|---|
| 117 | 'date' => $date, |
|---|
| 118 | $hour => "1", |
|---|
| 119 | ) |
|---|
| 120 | ); |
|---|
| 121 | if ($ret_date && $ret_png) return true; |
|---|
| 122 | else return false; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | ?> |
|---|