-
Notifications
You must be signed in to change notification settings - Fork 0
/
CashFiles.php
76 lines (72 loc) · 2.16 KB
/
CashFiles.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
<?php
class CashFiles
{
private function createImage($imgURL){
for($i = 0; $i < 10; $i++){
$img = imagecreatefromjpeg($imgURL);
$i++;
if ($img){
break;
}
sleep(0.5);
}
if (!($img)){
return "!!! Some image can not be downloaded !!!\n!!! CHECK CONNOCTION TO INTERNET !!!";
}else{
return $img;
}
}
private function waiter($results){
echo "Waiting fot workers...Cash for file\n";
for($i = 0; $i<180;$i++){
$flag = true;
foreach ($results as $file) {
if(!(file_exists($file))){
$flag = false;
break;
}
}
if($flag){
break;
}
sleep(1);
}
if(!$flag){
print "---------------------------------
\n!!! Oops something went wrong !!!
\n !!! Check the connection !!!
\n---------------------------------\n";
exit;
}
}
/*
in: $arrayShutter: array('id' => 'ID on Shutter', 'thumb' => 'Thumb on Shutter')
result: $arrayShutter: array('id' => 'ID on Shutter', 'thumb' => 'adress of file')
*/
public function CashShutter($arrayShutter, $folder ){
$arrayShutterNew = array();
$i = 0;
while ($i < count($arrayShutter)){
$results = array();
for ($ii = 0; $ii < 200; $ii++){
$adress = './' . $folder . '/ShutterFiles/' . $arrayShutter[$i]['id'] . '.jpg';
$results[] = $adress;
exec("php workerCashFiles.php ".$arrayShutter[$i]['thumb']." ".$adress." >> /dev/null &");
$arrayShutterNew[] = array('id' => $arrayShutter[$i]['id'], 'thumb' => $adress);
$i++;
if($i == count($arrayShutter)){break;}
}
$this->waiter($results);
}
return $arrayShutterNew;
}
public function CashDeposit($arrayDeposit, $folder){
$arrayDepositNew = array();
foreach ($arrayDeposit as $id => $file) {
$adress = './' . $folder . '/DepositFiles/' . $id . '.jpg';
imagejpeg($this->createImage($file) , $adress);
$arrayDepositNew[$id] = $adress;
}
return $arrayDepositNew;
}
}