4 define('WEB_URL', 'http://localhost/curl-de-sac');
5 define('DBG_LEVEL', 0);
9 require_once($G_base . 'Obj/curl-de-sac.phh');
11 class short_cmd extends CDS_cmd {
14 function short_cmd($cmd_cls, $ch, $short_data)
16 parent::__construct($cmd_cls, $ch);
17 $this->short_data = $short_data;
21 class short_cmd_cls extends CDS_cmd_cls {
22 function short_cmd_cls()
24 parent::__construct("short", 10);
27 function create($cds, $url)
29 if ($cds->dbg_get() > 0) {
30 printf("'short'::create url:[%s]\n", $url);
34 if (($ch = parent::pre_create($cds, $url)) == FALSE)
37 if (parent::create($cds, $ch) == FALSE)
40 $cmd = new short_cmd($this, $ch, "none currently");
48 function process($cmd, $ret)
50 if ($this->dbg_get() > 2) { printf("CURL: 'short' process: curl_multi_getcontent\n"); }
52 $content = curl_multi_getcontent($cmd->ch_get());
53 if ($this->dbg_get() > 0) { printf("'short' process: [%s]\n", $content); }
58 function timeout($cmd)
60 printf("'Short' timeout function reached\n");
64 class long_cmd extends CDS_cmd {
67 function long_cmd($cmd_cls, $ch, $long_data)
69 parent::__construct($cmd_cls, $ch);
70 $this->long_data = $long_data;
74 class long_cmd_cls extends CDS_cmd_cls {
75 function long_cmd_cls()
77 parent::__construct("long", 5);
80 function create($cds, $url)
82 if ($cds->dbg_get() > 0) {
83 printf("'long'::create url:[%s]\n", $url);
87 if (($ch = parent::pre_create($cds, $url)) == FALSE)
90 if (parent::create($cds, $ch) == FALSE)
93 $cmd = new long_cmd($this, $ch, "none currently");
101 function process($cmd, $ret)
103 if ($this->dbg_get() > 2) { printf("CURL: 'long' process: curl_multi_getcontent\n"); }
105 $content = curl_multi_getcontent($cmd->ch_get());
106 if ($this->dbg_get() > 0) { printf("'long' process: [%s]\n", $content); }
111 function timeout($cmd)
113 printf("'Long' timeout function reached\n");
122 $cds = new Curl_de_sac($debug);
125 $short_cls = new short_cmd_cls();
127 // registrer short_cls
128 printf("MAIN: Register 'short_cls'\n");
129 if (($cds->cmd_cls_register($short_cls)) == FALSE) {
130 fprintf(STDERR, "MAIN: 'short_cls' registration failed\n");
135 $long_cls = new long_cmd_cls();
138 printf("MAIN: Register 'long_cls'\n");
139 if (($cds->cmd_cls_register($long_cls)) == FALSE) {
140 fprintf(STDERR, "MAIN: 'long_cls' registration failed\n");
144 // register long_cls (retry)
145 printf("MAIN: Re-register 'long_cls' (must go wrong)\n");
146 if (($cds->cmd_cls_register($long_cls)) != FALSE) {
147 fprintf(STDERR, "MAIN: 'long_cls' re-registration success\n");
151 printf("MAIN: CDS:\n");
152 if (($debug & 1) == 1)
154 printf("MAIN: Deregister 'long_cls'\n");
155 if (($cds->cmd_cls_deregister($long_cls)) == FALSE) {
156 fprintf(STDERR, "MAIN: 'long_cls' deregistration failed\n");
160 if (($debug & 1) == 1) {
165 // re-re-register long_cls
166 printf("MAIN: Re-re-register 'long_cls'\n");
167 if (($cds->cmd_cls_register($long_cls)) == FALSE) {
168 fprintf(STDERR, "MAIN: 'long_cls' re-re-registration failed\n");
172 printf("MAIN: Deregister all\n");
173 $cds->cmd_cls_deregister_all();
175 // registrer short_cls
176 printf("MAIN: register 'short_cls'\n");
177 if (($cds->cmd_cls_register($short_cls, 10)) == FALSE) {
178 fprintf(STDERR, "MAIN: 'short_cls' registration failed\n");
183 printf("MAIN: register 'long_cls'\n");
184 if (($cds->cmd_cls_register($long_cls, 4)) == FALSE) {
185 fprintf(STDERR, "MAIN: 'long_cls' registration failed\n");
189 if (($debug & 1) == 1) {
195 // for ($i = -15 ; $i < 30 ; $i++) {
196 for ($i = 0 ; $i < 20 ; $i++) {
197 printf("MAIN: START ITERATION %d\n", $i);
200 printf("MAIN: load 'short'\n");
201 if ($cds->execute("short", WEB_URL.'/test/short.php') == FALSE) {
202 printf("MAIN: push 'short' command failed\n");
208 printf("MAIN: load 'short'\n");
209 if ($cds->execute("short", WEB_URL.'/test/short.php') == FALSE) {
210 printf("MAIN: push 'short' command failed\n");
216 printf("MAIN: load 'long'\n");
217 if ($cds->execute("long", WEB_URL.'/test/long.php') == FALSE) {
218 printf("MAIN: push 'long' command failed\n");
224 if (($debug & 1) == 1) {
230 printf("MAIN: Call process\n");
234 printf("MAIN: finished, dump cds:\n");
238 // if input data execute some command
239 // if end => clean exit