Created
May 30, 2019 16:04
-
-
Save elexfreeman/826ad9f2a46fec46e782a0df7cff2841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* тут подключения к базе и т.д. */ | |
/* лучше такую обработку делать на C++ */ | |
/* php будет трудно работать с памятью, может течь */ | |
class EmailData { | |
/* список доменов */ | |
/* $domain['gmail.com'] = 20; */ | |
public $domains = []; | |
/** | |
* Возвращает выборку из таблицы пользователей | |
*/ | |
public function getData($offset, $limit) { | |
return []; | |
} | |
public function parseEmail($email) { | |
if(length($email) == 0) { | |
return 'non'; | |
} | |
if(strripos($email, '@')===false) { | |
return 'non'; | |
} | |
return explode('@', $email)[1]; | |
} | |
/* собственно функция запуска */ | |
public function run() { | |
/* параметры выборки */ | |
/* мы не знаем сколько записей в БД */ | |
$limit = 10; | |
$offset = 0; | |
$this->domains = []; | |
while (true) { | |
/* Освобождаем память от предыдущих даннных */ | |
unset($data); | |
/* плучаем порцию данных об юзерах]] */ | |
$data = $this->getData($offset, $limit); | |
/* перебераем их */ | |
foreach($data as $key => $row) { | |
/* подсчет доменов */ | |
unset($emails); | |
$emails = explode(',', $row['email']); | |
foreach($row as $k => $field) { | |
$this->domains[$this->parseEmail($field['email'])] = $this->domains[$this->parseEmail($field['email'])] + 1; | |
} | |
} | |
/* если выборка меньше лимита значит мы подошли к концу списка юзеров */ | |
if(length($data) < $limit) { | |
break; | |
} | |
$offset = $offset + $limit; | |
} | |
/* убераем странные домены */ | |
unset( $this->domains['non']); | |
return $this->domains; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment