@@ -6,6 +6,8 @@ class PHPGlances{
6
6
private $ _url ;
7
7
private $ _port = 80 ;
8
8
private $ _error = '' ;
9
+ private $ _useCache = false ;
10
+ private $ _arrCache = array ();
9
11
10
12
private $ _oCurl ;
11
13
private $ _extPHPCurl ;
@@ -14,13 +16,12 @@ class PHPGlances{
14
16
private $ _extPHPSimpleXML ;
15
17
16
18
public function __construct ($ psURL , $ piPort ){
17
- $ this ->_url = $ psURL ;
18
- $ this ->_port = $ piPort ;
19
+ $ this ->_url = $ psURL ;
20
+ $ this ->_port = $ piPort ;
19
21
20
-
21
- $ this ->_extPHPCurl = extension_loaded ('curl ' );
22
- $ this ->_extPHPJson = extension_loaded ('json ' );
23
- $ this ->_extPHPXMLRPC = extension_loaded ('xmlrpc ' );
22
+ $ this ->_extPHPCurl = extension_loaded ('curl ' );
23
+ $ this ->_extPHPJson = extension_loaded ('json ' );
24
+ $ this ->_extPHPXMLRPC = extension_loaded ('xmlrpc ' );
24
25
$ this ->_extPHPSimpleXML = extension_loaded ('simplexml ' );
25
26
if ($ this ->_extPHPCurl == true ){
26
27
$ this ->_oCurl = curl_init ();
@@ -347,6 +348,26 @@ public function getError(){
347
348
return $ this ->_error ;
348
349
}
349
350
351
+ /**
352
+ * Enable or disable the cache
353
+ * @param boolean $bUseCache
354
+ * @return $this
355
+ * @author Progi1984
356
+ */
357
+ public function setCacheStatus ($ bUseCache ){
358
+ $ this ->_useCache = $ bUseCache ;
359
+ return $ this ;
360
+ }
361
+
362
+ /**
363
+ * Get the cache status
364
+ * @return bool
365
+ * @author Progi1984
366
+ */
367
+ public function getCacheStatus (){
368
+ return $ this ->_useCache ;
369
+ }
370
+
350
371
/**
351
372
* @return array
352
373
* @author Progi1984
@@ -360,7 +381,14 @@ public function getCore(){
360
381
}
361
382
362
383
private function getCpu (){
363
- return $ this ->fn_json_decode ($ this ->_api ('getCpu ' ), true );
384
+ if ($ this ->_useCache ){
385
+ if (!isset ($ this ->_arrCache ['getCpu ' ])){
386
+ $ this ->_arrCache ['getCpu ' ] = $ this ->fn_json_decode ($ this ->_api ('getCpu ' ), true );
387
+ }
388
+ return $ this ->_arrCache ['getCpu ' ];
389
+ } else {
390
+ return $ this ->fn_json_decode ($ this ->_api ('getCpu ' ), true );
391
+ }
364
392
}
365
393
public function cpu_getIOWait (){
366
394
$ res = $ this ->getCpu ();
@@ -436,7 +464,14 @@ public function cpu_getNice(){
436
464
}
437
465
438
466
private function getDiskIO (){
439
- return $ this ->fn_json_decode ($ this ->_api ('getDiskIO ' ), true );
467
+ if ($ this ->_useCache ){
468
+ if (!isset ($ this ->_arrCache ['getDiskIO ' ])){
469
+ $ this ->_arrCache ['getDiskIO ' ] = $ this ->fn_json_decode ($ this ->_api ('getDiskIO ' ), true );
470
+ }
471
+ return $ this ->_arrCache ['getDiskIO ' ];
472
+ } else {
473
+ return $ this ->fn_json_decode ($ this ->_api ('getDiskIO ' ), true );
474
+ }
440
475
}
441
476
public function diskIO_getCount (){
442
477
$ res = $ this ->getDiskIO ();
@@ -484,7 +519,14 @@ public function diskIO_getWriteBytes($piIdx){
484
519
}
485
520
486
521
private function getFs (){
487
- return $ this ->fn_json_decode ($ this ->_api ('getFs ' ), true );
522
+ if ($ this ->_useCache ){
523
+ if (!isset ($ this ->_arrCache ['getFs ' ])){
524
+ $ this ->_arrCache ['getFs ' ] = $ this ->fn_json_decode ($ this ->_api ('getFs ' ), true );
525
+ }
526
+ return $ this ->_arrCache ['getFs ' ];
527
+ } else {
528
+ return $ this ->fn_json_decode ($ this ->_api ('getFs ' ), true );
529
+ }
488
530
}
489
531
public function fs_getCount (){
490
532
$ res = $ this ->getFs ();
@@ -568,7 +610,14 @@ public function fs_getSize($piIdx){
568
610
}
569
611
570
612
private function getLoad (){
571
- return $ this ->fn_json_decode ($ this ->_api ('getLoad ' ), true );
613
+ if ($ this ->_useCache ){
614
+ if (!isset ($ this ->_arrCache ['getLoad ' ])){
615
+ $ this ->_arrCache ['getLoad ' ] = $ this ->fn_json_decode ($ this ->_api ('getLoad ' ), true );
616
+ }
617
+ return $ this ->_arrCache ['getLoad ' ];
618
+ } else {
619
+ return $ this ->fn_json_decode ($ this ->_api ('getLoad ' ), true );
620
+ }
572
621
}
573
622
public function load_getMin1 (){
574
623
$ res = $ this ->getLoad ();
@@ -608,7 +657,14 @@ public function load_getMin15(){
608
657
}
609
658
610
659
private function getLimits (){
611
- return $ this ->fn_json_decode ($ this ->_api ('getAllLimits ' ), true );
660
+ if ($ this ->_useCache ){
661
+ if (!isset ($ this ->_arrCache ['getAllLimits ' ])){
662
+ $ this ->_arrCache ['getAllLimits ' ] = $ this ->fn_json_decode ($ this ->_api ('getAllLimits ' ), true );
663
+ }
664
+ return $ this ->_arrCache ['getAllLimits ' ];
665
+ } else {
666
+ return $ this ->fn_json_decode ($ this ->_api ('getAllLimits ' ), true );
667
+ }
612
668
}
613
669
public function limit_getSTD (){
614
670
$ res = $ this ->getLimits ();
@@ -744,7 +800,14 @@ public function limit_getSWAP(){
744
800
}
745
801
746
802
private function getMem (){
747
- return $ this ->fn_json_decode ($ this ->_api ('getMem ' ), true );
803
+ if ($ this ->_useCache ){
804
+ if (!isset ($ this ->_arrCache ['getMem ' ])){
805
+ $ this ->_arrCache ['getMem ' ] = $ this ->fn_json_decode ($ this ->_api ('getMem ' ), true );
806
+ }
807
+ return $ this ->_arrCache ['getMem ' ];
808
+ } else {
809
+ return $ this ->fn_json_decode ($ this ->_api ('getMem ' ), true );
810
+ }
748
811
}
749
812
public function mem_getInactive (){
750
813
$ res = $ this ->getMem ();
@@ -844,7 +907,14 @@ public function mem_getFree(){
844
907
}
845
908
846
909
private function getMemSwap (){
847
- return $ this ->fn_json_decode ($ this ->_api ('getMemSwap ' ), true );
910
+ if ($ this ->_useCache ){
911
+ if (!isset ($ this ->_arrCache ['getMemSwap ' ])){
912
+ $ this ->_arrCache ['getMemSwap ' ] = $ this ->fn_json_decode ($ this ->_api ('getMemSwap ' ), true );
913
+ }
914
+ return $ this ->_arrCache ['getMemSwap ' ];
915
+ } else {
916
+ return $ this ->fn_json_decode ($ this ->_api ('getMemSwap ' ), true );
917
+ }
848
918
}
849
919
public function memswap_getTotal (){
850
920
$ res = $ this ->getMemSwap ();
@@ -884,7 +954,14 @@ public function memswap_getUsed(){
884
954
}
885
955
886
956
private function getNetwork (){
887
- return $ this ->fn_json_decode ($ this ->_api ('getNetwork ' ), true );
957
+ if ($ this ->_useCache ){
958
+ if (!isset ($ this ->_arrCache ['getNetwork ' ])){
959
+ $ this ->_arrCache ['getNetwork ' ] = $ this ->fn_json_decode ($ this ->_api ('getNetwork ' ), true );
960
+ }
961
+ return $ this ->_arrCache ['getNetwork ' ];
962
+ } else {
963
+ return $ this ->fn_json_decode ($ this ->_api ('getNetwork ' ), true );
964
+ }
888
965
}
889
966
public function network_getCount (){
890
967
$ res = $ this ->getNetwork ();
@@ -936,7 +1013,14 @@ public function getNow(){
936
1013
}
937
1014
938
1015
private function getProcessCount (){
939
- return $ this ->fn_json_decode ($ this ->_api ('getProcessCount ' ), true );
1016
+ if ($ this ->_useCache ){
1017
+ if (!isset ($ this ->_arrCache ['getProcessCount ' ])){
1018
+ $ this ->_arrCache ['getProcessCount ' ] = $ this ->fn_json_decode ($ this ->_api ('getProcessCount ' ), true );
1019
+ }
1020
+ return $ this ->_arrCache ['getProcessCount ' ];
1021
+ } else {
1022
+ return $ this ->fn_json_decode ($ this ->_api ('getProcessCount ' ), true );
1023
+ }
940
1024
}
941
1025
public function processcount_getZombie (){
942
1026
$ res = $ this ->getProcessCount ();
@@ -988,7 +1072,14 @@ public function processcount_getSleeping(){
988
1072
}
989
1073
990
1074
private function getProcessList (){
991
- return $ this ->fn_json_decode ($ this ->_api ('getProcessList ' ), true );
1075
+ if ($ this ->_useCache ){
1076
+ if (!isset ($ this ->_arrCache ['getProcessList ' ])){
1077
+ $ this ->_arrCache ['getProcessList ' ] = $ this ->fn_json_decode ($ this ->_api ('getProcessList ' ), true );
1078
+ }
1079
+ return $ this ->_arrCache ['getProcessList ' ];
1080
+ } else {
1081
+ return $ this ->fn_json_decode ($ this ->_api ('getProcessList ' ), true );
1082
+ }
992
1083
}
993
1084
public function processlist_getCount (){
994
1085
$ res = $ this ->getProcessList ();
@@ -1132,7 +1223,14 @@ public function processlist_getNice($piIdx){
1132
1223
}
1133
1224
1134
1225
private function getSensors (){
1135
- return $ this ->fn_json_decode ($ this ->_api ('getSensors ' ), true );
1226
+ if ($ this ->_useCache ){
1227
+ if (!isset ($ this ->_arrCache ['getSensors ' ])){
1228
+ $ this ->_arrCache ['getSensors ' ] = $ this ->fn_json_decode ($ this ->_api ('getSensors ' ), true );
1229
+ }
1230
+ return $ this ->_arrCache ['getSensors ' ];
1231
+ } else {
1232
+ return $ this ->fn_json_decode ($ this ->_api ('getSensors ' ), true );
1233
+ }
1136
1234
}
1137
1235
public function sensors_getCount (){
1138
1236
$ res = $ this ->getSensors ();
@@ -1168,7 +1266,14 @@ public function sensors_getLabel($piIdx){
1168
1266
}
1169
1267
1170
1268
private function getSystem (){
1171
- return $ this ->fn_json_decode ($ this ->_api ('getSystem ' ), true );
1269
+ if ($ this ->_useCache ){
1270
+ if (!isset ($ this ->_arrCache ['getSystem ' ])){
1271
+ $ this ->_arrCache ['getSystem ' ] = $ this ->fn_json_decode ($ this ->_api ('getSystem ' ), true );
1272
+ }
1273
+ return $ this ->_arrCache ['getSystem ' ];
1274
+ } else {
1275
+ return $ this ->fn_json_decode ($ this ->_api ('getSystem ' ), true );
1276
+ }
1172
1277
}
1173
1278
public function system_getLinuxDistro (){
1174
1279
$ res = $ this ->getSystem ();
0 commit comments