-
Notifications
You must be signed in to change notification settings - Fork 0
/
disoveryset.php
44 lines (36 loc) · 1.33 KB
/
disoveryset.php
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
35
36
37
38
39
40
41
42
43
44
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
if (!ini_get('safe_mode')) {
set_time_limit(0);
ini_set('memory_limit', '512M');
}
require_once('includes.php');
require_once('SMNIncludes.php');
$existing_users = SMNUserQueries::allUsers();
$number = count($existing_users);
echo "Caching " . $number . " user discoveries <br/>" . PHP_EOL;
$elapsed = 0;
$average_time = 0;
$remaining_est_time = 0;
$elapsed_time = 0;
foreach ($existing_users as $user) {
list($usec, $sec) = explode(' ', microtime());
$script_start = (float) $sec + (float) $usec;
$ourFileName = $user . ".json";
$fh = fopen(dirname(__FILE__) . "/api/cached_discovery/" . $ourFileName, 'w');
$results = SMNUserFinder::findRelatedUsers($user, null, null, null);
$json_results = json_encode($results);
fwrite($fh, $json_results);
fclose($fh);
list($usec, $sec) = explode(' ', microtime());
$script_end = (float) $sec + (float) $usec;
$elapsed_time += round($script_end - $script_start, 5);
$elapsed+=1;
$average_time = $elapsed_time / $elapsed;
$remaining_est_time = ($number - $elapsed) * $average_time;
echo "Done: " . $elapsed . " users - Time: " . convertTime($elapsed_time) . " Est Remaining: " . convertTime($remaining_est_time) . '<br />' . PHP_EOL;
}
?>