/
index.php
42 lines (36 loc) · 955 Bytes
/
index.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
<?php
if(!$_POST){
require "page.html";
} else {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
queueAssignment($name, $email, $phone);
header("Location: success.html");
}
/**
* This function will take 3 arguments and pass it to gearman worker to store in database
*/
function queueAssignment($name, $email, $phone) {
$detailsArray = array('name' => $name, 'email' => $email, 'phone' => $phone);
$detailsStr = json_encode($detailsArray);
writeFile($detailsArray);
// client code
$client = new GearmanClient();
$client->addServer();
$store = $client->do("saveRecord", $detailsStr);
}
/**
* This function will take the data and stores in json file
*/
function writeFile($data) {
$my_file = "users.json";
$users = [];
if(file_exists($my_file)){
$users = json_decode(file_get_contents($my_file), true);
}
$users[] = $data;
$jsonData = json_encode($users);
file_put_contents($my_file, $jsonData);
}
?>