4 define('WEBURL', 'http://localhost/curl-de-sac');
6 require_once('Obj/curl-de-sac.phh');
8 class short_cmd extends CDS_cmd {
11 function short_cmd($cmd_cls, $ch, $short_data)
13 parent::__construct($cmd_cls, $ch);
14 $this->short_data = $short_data;
18 class short_cmd_cls extends CDS_cmd_cls {
19 function short_cmd_cls()
21 parent::__construct("short", 10);
24 function create($cds, $url)
26 if ($cds->dbg_get() > 0) {
27 printf("short::create url:[%s]\n", $url);
31 if (($ch = parent::pre_create($cds, $url)) == FALSE)
34 if (parent::create($cds, $ch) == FALSE)
37 $cmd = new short_cmd($this, $ch, "none currently");
45 function process($cmd, $ret)
47 printf("CURL: curl_multi_getcontent\n");
48 $content = curl_multi_getcontent($cmd->ch_get());
49 if ($this->dbg_get() > 0) {
50 printf("short process: [%s]\n", $content);
55 function timeout($cmd)
57 printf("Short timeout function reached\n");
61 class long_cmd extends CDS_cmd {
64 function long_cmd($cmd_cls, $ch, $long_data)
66 parent::__construct($cmd_cls, $ch);
67 $this->long_data = $long_data;
71 class long_cmd_cls extends CDS_cmd_cls {
72 function long_cmd_cls()
74 parent::__construct("long", 5);
77 function create($cds, $url)
79 if ($cds->dbg_get() > 0) {
80 printf("long::create url:[%s]\n", $url);
84 if (($ch = parent::pre_create($cds, $url)) == FALSE)
87 if (parent::create($cds, $ch) == FALSE)
90 $cmd = new long_cmd($this, $ch, "none currently");
98 function process($cmd, $ret)
100 printf("CURL: curl_multi_getcontent\n");
101 $content = curl_multi_getcontent($cmd->ch_get());
102 if ($this->dbg_get() > 0) {
103 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 cds_cmd 1
126 printf("MAIN: Register CLS1\n");
127 if (($cds->cmd_cls_register($short_cls)) == FALSE) {
128 fprintf(STDERR, "MAIN: cmd_cls1 registration failed\n");
133 $long_cls = new long_cmd_cls();
135 // register cds_cmd 2
136 printf("MAIN: Register CLS2\n");
137 if (($cds->cmd_cls_register($long_cls)) == FALSE) {
138 fprintf(STDERR, "MAIN: cmd_cls2 registration failed\n");
142 // register cds_cmd 2 (retry)
143 printf("MAIN: Re-register CLS2 (must go wrong)\n");
144 if (($cds->cmd_cls_register($long_cls)) != FALSE) {
145 fprintf(STDERR, "MAIN: cmd_cls2 re-registration success\n");
149 printf("MAIN: CDS:\n");
150 if (($debug & 1) == 1)
152 printf("MAIN: Deregister CLS2\n");
153 if (($cds->cmd_cls_deregister($long_cls)) == FALSE) {
154 fprintf(STDERR, "MAIN: cmd_cls2 deregistration failed\n");
158 if (($debug & 1) == 1) {
163 // re-re-register cds_cmd 2
164 printf("MAIN: Re-re-register CLS2\n");
165 if (($cds->cmd_cls_register($long_cls)) == FALSE) {
166 fprintf(STDERR, "MAIN: cmd_cls2 re-re-registration failed\n");
170 printf("MAIN: Deregister all\n");
171 $cds->cmd_cls_deregister_all();
173 // registrer cds_cmd 1
174 printf("MAIN: register CLS1\n");
175 if (($cds->cmd_cls_register($short_cls, 10)) == FALSE) {
176 fprintf(STDERR, "MAIN: cmd_cls1 registration failed\n");
180 // register cds_cmd 2
181 printf("MAIN: register CLS2\n");
182 if (($cds->cmd_cls_register($long_cls, 4)) == FALSE) {
183 fprintf(STDERR, "MAIN: cmd_cls2 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", WEBURL.'/short.php') == FALSE) {
200 printf("MAIN: push command failed\n");
206 printf("MAIN: load short\n");
207 if ($cds->execute("short", WEBURL.'/short.php') == FALSE) {
208 printf("MAIN: push command failed\n");
214 printf("MAIN: load long\n");
215 if ($cds->execute("long", WEBURL.'/long.php') == FALSE) {
216 printf("MAIN: push 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