-
Notifications
You must be signed in to change notification settings - Fork 0
/
ejemplo_con_thread.php
79 lines (71 loc) · 1.27 KB
/
ejemplo_con_thread.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
gc_disable();
$hora = new DateTime();
$empieza = $hora->getTimestamp();
function asignarDatos($csvFile)
{
require 'vendor/autoload.php';
$faker = Faker\Factory::create('es_ES');
$csv = fopen($csvFile, "a");
fputcsv($csv, array(
'Id',
'Ingresado',
'Nombre(s)',
'Apellido(s)',
'Email',
'Email Empresa',
'Telefono',
'Movil',
'Ip',
'Empresa',
'Puesto',
'Direccion',
));
foreach(range(1,6000) as $i)
{
echo(".");
fputcsv($csv, array(
$i,
$faker->unixTime,
$faker->firstName,
$faker->lastName,
$faker->email,
$faker->companyEmail,
$faker->phoneNumber,
$faker->e164PhoneNumber,
$faker->ipv6,
$faker->company,
$faker->jobTitle,
$faker->address,
));
}
fclose($csv);
}
class hiloDeProceso extends Thread
{
private $workerId;
private $csvFile;
public function __construct($id, $csvFile)
{
$this->workerId = $id;
$this->csvFile = $csvFile.$id.".csv";
}
public function run()
{
asignarDatos( $this->csvFile);
}
}
$proc = array();
foreach(range(1,4) as $i)
{
$proc[$i] = new hiloDeProceso($i, "salida_datos");
$proc[$i]->start();
}
foreach(range(1,4) as $i)
{
$proc[$i]->join();
}
$hora = new DateTime();
$termina = $hora->getTimestamp();
echo("\nTardó apróximadamente: ".($termina - $empieza)."segs.\n");
?>