Skip to content
This repository has been archived by the owner on Oct 18, 2019. It is now read-only.

php single thead implementation #12

Merged
merged 1 commit into from Sep 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions php/search.php
@@ -0,0 +1,34 @@
<?php
class Hash {
public function __get($key)
{
$this->$key = 0;
return 0;
}
}
$result = new Hash();
$dir = __DIR__ . '/../tmp/tweets';
foreach(scandir($dir) as $file) {
if ($file === '.' || $file === '..') {
continue;
}

$fh = fopen($dir . '/' . $file, 'r');
while($line = fgets($fh)) {
if (stripos($line, 'knicks') !== false) {
list($_, $hood) = explode("\t", $line, 3);
$result->$hood++;
}
}
fclose($fh);
}
$result = (array)$result;
arsort($result);
$fh = fopen($dir . '/../php_output', 'w');
foreach($result as $hood => $count) {
fwrite($fh, $hood);
fwrite($fh, "\t");
fwrite($fh, $count);
fwrite($fh, "\n");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you use 4th write operation instead 1?

}
fclose($fh);
4 changes: 4 additions & 0 deletions run_php
@@ -0,0 +1,4 @@
#!/bin/bash

export TIMEFORMAT=%R
time php php/search.php