4
4
*
5
5
* @author G. Giunta
6
6
* @license GNU GPL 2.0
7
- * @copyright (C) G. Giunta 2010-2012
7
+ * @copyright (C) G. Giunta 2010-2019
8
8
*
9
9
* It uses curl for executing the http requests.
10
10
* It uses a multi-process scheme (tested to be working both on windows and linux):
27
27
28
28
if ( !defined ( 'EZAB_AS_LIB ' ) )
29
29
{
30
- if ( !function_exists ( 'curl_init ' ) )
30
+ if ( !function_exists ( 'curl_init ' ) )
31
31
{
32
32
echo ( 'Missing cURL, cannot run ' );
33
33
exit ( 1 );
50
50
51
51
class eZAB
52
52
{
53
- static $ version = '0.3-dev ' ;
53
+ static $ version = '0.3 ' ;
54
54
static $ defaults = array (
55
55
// 'real' options
56
56
/// How much troubleshooting info to print. According to ab docs:
57
57
/// "4 and above prints information on headers, 3 and above prints response codes (404, 200, etc.), 2 and above prints warnings and info."
58
58
/// Real life testing seem to tell a different story though...
59
59
'verbosity ' => 1 , // -v verbosity
60
60
'children ' => 1 , // -c concurrency Number of multiple requests to make
61
- 'tries ' => 1 , // -n requests Number of requests to perform
62
- 'timeout ' => 0 , // -t timelimit Seconds to max. wait for responses
61
+ 'tries ' => 1 , // -n requests Number of requests to perform
62
+ 'timeout ' => 0 , // -t timelimit Seconds to max. wait for responses
63
63
'auth ' => false ,
64
64
'proxy ' => false ,
65
65
'proxyauth ' => false ,
@@ -97,6 +97,7 @@ function __construct( $opts = array() )
97
97
/**
98
98
* Actual execution of the test, echoes results to stdout.
99
99
* Depending on options, calls runParent or runChild, or echoes help messages
100
+ * @throws Exception
100
101
*/
101
102
public function run ()
102
103
{
@@ -114,14 +115,15 @@ public function run()
114
115
echo $ this ->helpMsg ();
115
116
break ;
116
117
default :
117
- $ this ->abort ( 1 , 'Unkown running mode: ' . $ this ->opts ['command ' ] );
118
+ $ this ->abort ( 1 , 'Unknown running mode: ' . $ this ->opts ['command ' ] );
118
119
}
119
120
}
120
121
121
122
/**
122
123
* Runs the test, prints results (unless verbosity option has been set to 0).
123
124
* Note: sets a value to $this->opts['parentid'], too
124
125
* @return array
126
+ * @throws Exception
125
127
*/
126
128
public function runParent ()
127
129
{
@@ -207,7 +209,7 @@ public function runParent()
207
209
//$starttimes = array();
208
210
$ pipes = array ();
209
211
$ childprocs = array ();
210
- $ childresults = array ();
212
+ // $childresults = array();
211
213
212
214
//$time = microtime( true );
213
215
@@ -241,7 +243,7 @@ public function runParent()
241
243
// wait for all children to finish
242
244
/// @todo add a global timeout limit?
243
245
$ finished = 0 ;
244
- $ outputs = array ();
246
+ // $outputs = array();
245
247
do
246
248
{
247
249
/// @todo !important lower this - use usleep
@@ -423,7 +425,7 @@ public function runChild()
423
425
if ( $ curl )
424
426
{
425
427
curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER , true );
426
- // enbale receiving header too. We will need later to split by ourselves headers from body to calculate correct sizes
428
+ // enable receiving header too. We will need later to split by ourselves headers from body to calculate correct sizes
427
429
curl_setopt ( $ curl , CURLOPT_HEADER , true );
428
430
curl_setopt ( $ curl , CURLOPT_USERAGENT , "eZAB " . self ::$ version );
429
431
if ( $ opts ['timeout ' ] > 0 )
@@ -578,7 +580,7 @@ public function runChild()
578
580
}
579
581
580
582
/**
581
- * Parse the ouput of children processes and calculate global stats
583
+ * Parse the output of children processes and calculate global stats
582
584
*/
583
585
protected function parseOutputs ( $ outputs )
584
586
{
@@ -692,9 +694,13 @@ protected function parseOutputs( $outputs )
692
694
return $ resp ;
693
695
}
694
696
697
+ /**
698
+ * @param string $php
699
+ * @return string
700
+ * @throws Exception
701
+ */
695
702
protected function getPHPExecutable ( $ php ='php ' )
696
703
{
697
- $ validExecutable = false ;
698
704
do
699
705
{
700
706
$ output = array ();
@@ -721,7 +727,8 @@ protected function getPHPExecutable( $php='php' )
721
727
/**
722
728
* Parses args in argc/argv format (stores them, unless -h or -V are found, in which case only $this->opts['self'] is set)
723
729
* If any unknown option is found, prints help msg and exit.
724
- * Nb: pre-existing otions are not reset by this call.
730
+ * Nb: pre-existing options are not reset by this call.
731
+ * @throws Exception
725
732
*/
726
733
public function parseArgs ( $ argv )
727
734
{
@@ -812,10 +819,10 @@ public function parseArgs( $argv )
812
819
$ opts ['childnr ' ] = (int )$ val ;
813
820
$ opts ['command ' ] = 'runchild ' ;
814
821
break ;
815
- case 'i ' :
822
+ case 'i ' :
816
823
$ opts ['head ' ] = true ;
817
824
break ;
818
- case 'j ' :
825
+ case 'j ' :
819
826
$ opts ['respencoding ' ] = true ;
820
827
break ;
821
828
case 'k ' :
@@ -1037,15 +1044,15 @@ function versionMsg()
1037
1044
if ( $ this ->opts ['outputformat ' ] == 'html ' )
1038
1045
$ out .= '<pre> ' ;
1039
1046
$ out .= "This is eZAB, Version " . self ::$ version . "\n" ;
1040
- $ out .= "Copyright 2010-2012 G. Giunta, eZ Systems, http://ez.no \n" ;
1047
+ $ out .= "Copyright 2010-2019 G. Giunta, eZ Systems, http://ez.no \n" ;
1041
1048
if ( $ this ->opts ['outputformat ' ] == 'html ' )
1042
1049
$ out .= '</pre> ' ;
1043
1050
return $ out ;
1044
1051
}
1045
1052
1046
1053
/**
1047
1054
* Either exits or throws an exception
1048
- *
1055
+ * @throws Exception
1049
1056
* @todo !important when in web mode, there is little sign that there was an error...
1050
1057
*/
1051
1058
protected function abort ( $ errcode =1 , $ msg ='' )
@@ -1074,5 +1081,3 @@ protected function abort( $errcode=1, $msg='' )
1074
1081
}
1075
1082
}
1076
1083
}
1077
-
1078
- ?>
0 commit comments