-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-to-firebase.php
48 lines (39 loc) · 1.47 KB
/
send-to-firebase.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
45
46
47
48
<?php
require __DIR__.'/vendor/autoload.php';
date_default_timezone_set('Asia/Taipei');
const DEFAULT_URL = 'https://{projectName}.firebaseio.com/';
const DEFAULT_TOKEN = '{yourToken}';
const DEFAULT_PATH = '/messages';
$firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);
$images = array(
'http://image.flaticon.com/icons/png/128/188/188996.png',
'http://image.flaticon.com/icons/png/128/188/188987.png',
'http://image.flaticon.com/icons/png/128/189/189006.png',
'http://image.flaticon.com/icons/png/128/189/189001.png',
'http://image.flaticon.com/icons/png/128/189/189000.png',
'http://image.flaticon.com/icons/png/128/188/188990.png'
);
$dateTime = new DateTime();
echo 'Start Time: ' . $dateTime->format('H:i:s');
$count = 0;
while ($count < 3000) {
if ($count % 12 === 0) {
$dateTime = new DateTime();
$message = array(
'time' => $dateTime->getTimestamp(),
'message' => 'Hello from PHP',
'id' => rand(1, 100),
'name' => 'PHP',
'image' => $images[rand(0, 5)]
);
$path = sprintf('%s/%s', DEFAULT_PATH, $message['time']);
$message['id'] = rand(1, 100);
$set = $firebase->set($path, $message);
echo 'Count = ' . $count . ' & ID = ' . $message['id'] . ' -> Success! ' . print_r($set, true) . PHP_EOL;
unset($dateTime);
}
$count += 1;
sleep(1);
}
$dateTime = new DateTime();
echo 'End Time: ' . $dateTime->format('H:i:s');