-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddLoad.php
More file actions
38 lines (27 loc) · 983 Bytes
/
addLoad.php
File metadata and controls
38 lines (27 loc) · 983 Bytes
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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once 'Core/Logger.php';
require_once 'Core/KafkaProducer.php';
$config_file = 'config_default.ini';
$config = parse_ini_file($config_file, true);
$db = 'wordpress';
$user = 'root';
$pass = 'pass';
$charset = 'utf8';
$dsn = "mysql:host=0;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$pdo = new PDO($dsn, $user, $pass, $opt);
$producer = new KafkaProducer($config);
for ($i = 0; $i <= 7927; $i += 10) {
$stmt = $pdo->query('SELECT ID, post_content FROM wp_posts LIMIT 10 OFFSET ' . $i);
while ($row = $stmt->fetch()) {
//$producer->send('my-docs', json_encode(['id' => $row['ID'], 'text' => $row['post_content']]));
$producer->send('my-docs', $row['post_content']);
}
}