4 define('WEB_URL', 'http://localhost/curl-de-sac');
5 define('DBG_LEVEL', 0);
7 require_once('Obj/curl-de-sac.phh');
9 class short_cmd extends CDS_cmd {
12 function short_cmd($cmd_cls, $ch, $short_data)
14 parent::__construct($cmd_cls, $ch);
15 $this->short_data = $short_data;
19 class short_cmd_cls extends CDS_cmd_cls {
20 function short_cmd_cls()
22 parent::__construct("short", 10);
25 function create($cds, $url)
27 if ($cds->dbg_get() > 0) {
28 printf("'short'::create url:[%s]\n", $url);
32 if (($ch = parent::pre_create($cds, $url)) == FALSE)
35 if (parent::create($cds, $ch) == FALSE)
38 $cmd = new short_cmd($this, $ch, "none currently");
46 function process($cmd, $ret)
48 if ($this->dbg_get() > 2) { printf("CURL: 'short' process: curl_multi_getcontent\n"); }
50 $content = curl_multi_getcontent($cmd->ch_get());
51 if ($this->dbg_get() > 0) { printf("'short' process: [%s]\n", $content); }
56 function timeout($cmd)
58 printf("'Short' timeout function reached\n");
62 class long_cmd extends CDS_cmd {
65 function long_cmd($cmd_cls, $ch, $long_data)
67 parent::__construct($cmd_cls, $ch);
68 $this->long_data = $long_data;
72 class long_cmd_cls extends CDS_cmd_cls {
73 function long_cmd_cls()
75 parent::__construct("long", 5);
78 function create($cds, $url)
80 if ($cds->dbg_get() > 0) {
81 printf("'long'::create url:[%s]\n", $url);
85 if (($ch = parent::pre_create($cds, $url)) == FALSE)
88 if (parent::create($cds, $ch) == FALSE)
91 $cmd = new long_cmd($this, $ch, "none currently");
99 function process($cmd, $ret)
101 if ($this->dbg_get() > 2) { printf("CURL: 'long' process: curl_multi_getcontent\n"); }
103 $content = curl_multi_getcontent($cmd->ch_get());
104 if ($this->dbg_get() > 0) { printf("'long' process: [%s]\n", $content); }
109 function timeout($cmd)
111 printf("'Long' timeout function reached\n");
120 $cds = new Curl_de_sac($debug);
123 $short_cls = new short_cmd_cls();
125 // registrer short_cls
126 printf("MAIN: Register 'short_cls'\n");
127 if (($cds->cmd_cls_register($short_cls)) == FALSE) {
128 fprintf(STDERR, "MAIN: 'short_cls' registration failed\n");
133 $long_cls = new long_cmd_cls();
136 printf("MAIN: Register 'long_cls'\n");
137 if (($cds->cmd_cls_register($long_cls)) == FALSE) {
138 fprintf(STDERR, "MAIN: 'long_cls' registration failed\n");
142 // register long_cls (retry)
143 printf("MAIN: Re-register 'long_cls' (must go wrong)\n");
144 if (($cds->cmd_cls_register($long_cls)) != FALSE) {
145 fprintf(STDERR, "MAIN: 'long_cls' re-registration success\n");
149 printf("MAIN: CDS:\n");
150 if (($debug & 1) == 1)
152 printf("MAIN: Deregister 'long_cls'\n");
153 if (($cds->cmd_cls_deregister($long_cls)) == FALSE) {
154 fprintf(STDERR, "MAIN: 'long_cls' deregistration failed\n");
158 if (($debug & 1) == 1) {
163 // re-re-register long_cls
164 printf("MAIN: Re-re-register 'long_cls'\n");
165 if (($cds->cmd_cls_register($long_cls)) == FALSE) {
166 fprintf(STDERR, "MAIN: 'long_cls' re-re-registration failed\n");
170 printf("MAIN: Deregister all\n");
171 $cds->cmd_cls_deregister_all();
173 // registrer short_cls
174 printf("MAIN: register 'short_cls'\n");
175 if (($cds->cmd_cls_register($short_cls, 10)) == FALSE) {
176 fprintf(STDERR, "MAIN: 'short_cls' registration failed\n");
181 printf("MAIN: register 'long_cls'\n");
182 if (($cds->cmd_cls_register($long_cls, 4)) == FALSE) {
183 fprintf(STDERR, "MAIN: 'long_cls' registration failed\n");
187 if (($debug & 1) == 1) {
193 // for ($i = -15 ; $i < 30 ; $i++) {
194 for ($i = 0 ; $i < 20 ; $i++) {
195 printf("MAIN: START ITERATION %d\n", $i);
198 printf("MAIN: load 'short'\n");
199 if ($cds->execute("short", WEB_URL.'/short.php') == FALSE) {
200 printf("MAIN: push 'short' command failed\n");
206 printf("MAIN: load 'short'\n");
207 if ($cds->execute("short", WEB_URL.'/short.php') == FALSE) {
208 printf("MAIN: push 'short' command failed\n");
214 printf("MAIN: load 'long'\n");
215 if ($cds->execute("long", WEB_URL.'/long.php') == FALSE) {
216 printf("MAIN: push 'long' command failed\n");
222 if (($debug & 1) == 1) {
228 printf("MAIN: Call process\n");
232 printf("MAIN: finished, dump cds:\n");
236 // if input data execute some command
237 // if end => clean exit