]> Raphaƫl G. Git Repositories - airbundle/blob - Command/WeatherCommand.php
Add note about validating app
[airbundle] / Command / WeatherCommand.php
1 <?php
2
3 namespace Rapsys\AirBundle\Command;
4
5 use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand;
6 use Doctrine\Persistence\ManagerRegistry;
7 use Symfony\Component\Console\Input\InputInterface;
8 use Symfony\Component\Console\Output\OutputInterface;
9 use Symfony\Component\Filesystem\Exception\IOException;
10 use Symfony\Component\Filesystem\Filesystem;
11
12 use Rapsys\AirBundle\Entity\Session;
13
14 class WeatherCommand extends DoctrineCommand {
15 //Set failure constant
16 const FAILURE = 1;
17
18 ///Set success constant
19 const SUCCESS = 0;
20
21 ///Set Tidy config
22 private $config = [
23 //Mostly useless in fact
24 'indent' => true,
25 //Required to simplify simplexml transition
26 'output-xml' => true,
27 //Required to avoid xml errors
28 'quote-nbsp' => false,
29 //Required to fix code
30 'clean' => true
31 ];
32
33 ///Set accuweather uris
34 private $accuweather = [
35 //Hourly uri
36 'hourly' => [
37 75001 => 'https://www.accuweather.com/en/fr/paris-01-louvre/75001/hourly-weather-forecast/179142_pc?day=',
38 75004 => 'https://www.accuweather.com/en/fr/paris-04-hotel-de-ville/75004/hourly-weather-forecast/179145_pc?day=',
39 75005 => 'https://www.accuweather.com/en/fr/paris-05-pantheon/75005/hourly-weather-forecast/179146_pc?day=',
40 75006 => 'https://www.accuweather.com/fr/fr/paris-06-luxembourg/75006/hourly-weather-forecast/179147_pc?day=',
41 75007 => 'https://www.accuweather.com/en/fr/paris-07-palais-bourbon/75007/hourly-weather-forecast/179148_pc?day=',
42 75009 => 'https://www.accuweather.com/en/fr/paris-09-opera/75009/hourly-weather-forecast/179150_pc?day=',
43 75012 => 'https://www.accuweather.com/en/fr/paris-12-reuilly/75012/hourly-weather-forecast/179153_pc?day=',
44 75013 => 'https://www.accuweather.com/en/fr/paris-13-gobelins/75013/hourly-weather-forecast/179154_pc?day=',
45 75015 => 'https://www.accuweather.com/en/fr/paris-15-vaugirard/75015/hourly-weather-forecast/179156_pc?day=',
46 75019 => 'https://www.accuweather.com/en/fr/paris-19-buttes-chaumont/75019/hourly-weather-forecast/179160_pc?day=',
47 75116 => 'https://www.accuweather.com/en/fr/paris-16-passy/75116/hourly-weather-forecast/179246_pc?day='
48 ],
49 //Daily uri
50 'daily' => [
51 75001 => 'https://www.accuweather.com/en/fr/paris-01-louvre/75001/daily-weather-forecast/179142_pc',
52 75004 => 'https://www.accuweather.com/en/fr/paris-04-hotel-de-ville/75004/daily-weather-forecast/179145_pc',
53 75005 => 'https://www.accuweather.com/en/fr/paris-05-pantheon/75005/daily-weather-forecast/179146_pc',
54 75006 => 'https://www.accuweather.com/fr/fr/paris-06-luxembourg/75006/daily-weather-forecast/179147_pc',
55 75007 => 'https://www.accuweather.com/en/fr/paris-07-palais-bourbon/75007/daily-weather-forecast/179148_pc',
56 75009 => 'https://www.accuweather.com/en/fr/paris-09-opera/75009/daily-weather-forecast/179150_pc',
57 75012 => 'https://www.accuweather.com/en/fr/paris-12-reuilly/75012/daily-weather-forecast/179153_pc',
58 75013 => 'https://www.accuweather.com/en/fr/paris-13-gobelins/75013/daily-weather-forecast/179154_pc',
59 75015 => 'https://www.accuweather.com/en/fr/paris-15-vaugirard/75015/daily-weather-forecast/179156_pc',
60 75019 => 'https://www.accuweather.com/en/fr/paris-19-buttes-chaumont/75019/daily-weather-forecast/179160_pc',
61 75116 => 'https://www.accuweather.com/en/fr/paris-16-passy/75116/daily-weather-forecast/179246_pc'
62 ]
63 ];
64
65 ///Set curl handler
66 private $ch = null;
67
68 ///Set manager registry
69 private $doctrine;
70
71 ///Set filesystem
72 private $filesystem;
73
74 ///Weather command constructor
75 public function __construct(ManagerRegistry $doctrine, Filesystem $filesystem) {
76 parent::__construct($doctrine);
77
78 //Set entity manager
79 $this->doctrine = $doctrine;
80
81 //Set filesystem
82 $this->filesystem = $filesystem;
83 }
84
85 ///Configure attribute command
86 protected function configure() {
87 //Configure the class
88 $this
89 //Set name
90 ->setName('rapsysair:weather')
91 //Set description shown with bin/console list
92 ->setDescription('Updates session rain and temperature fields')
93 //Set description shown with bin/console --help airlibre:attribute
94 ->setHelp('This command updates session rain and temperature fields in next three days')
95 //Add daily and hourly aliases
96 ->setAliases(['rapsysair:weather:daily', 'rapsysair:weather:hourly']);
97 }
98
99 ///Process the attribution
100 protected function execute(InputInterface $input, OutputInterface $output) {
101 //Kernel object
102 $kernel = $this->getApplication()->getKernel();
103
104 //Tmp directory
105 $tmpdir = $kernel->getContainer()->getParameter('kernel.project_dir').'/var/cache/weather';
106
107 //Set tmpdir
108 //XXX: worst case scenario we have 3 files per zipcode plus daily
109 if (!is_dir($tmpdir)) {
110 try {
111 //Create dir
112 $this->filesystem->mkdir($tmpdir, 0775);
113 } catch (IOException $exception) {
114 //Display error
115 echo 'Create dir '.$exception->getPath().' failed'."\n";
116
117 //Exit with failure
118 exit(self::FAILURE);
119 }
120 }
121
122 //Cleanup kernel
123 unset($kernel);
124
125 //Tidy object
126 $tidy = new \tidy();
127
128 //Init zipcodes array
129 $zipcodes = [];
130
131 //Init types
132 $types = [];
133
134 //Process hourly accuweather
135 if (($command = $input->getFirstArgument()) == 'rapsysair:weather:hourly' || $command == 'rapsysair:weather') {
136 //Fetch hourly sessions to attribute
137 $types['hourly'] = $this->doctrine->getRepository(Session::class)->findAllPendingHourlyWeather();
138
139 //Iterate on each session
140 foreach($types['hourly'] as $sessionId => $session) {
141 //Get zipcode
142 $zipcode = $session->getLocation()->getZipcode();
143
144 //Get start
145 $start = $session->getStart();
146
147 //Set start day
148 $day = $start->diff((new \DateTime('now'))->setTime(0, 0, 0))->d + 1;
149
150 //Check if zipcode is set
151 if (!isset($zipcodes[$zipcode])) {
152 $zipcodes[$zipcode] = [];
153 }
154
155 //Check if zipcode date is set
156 if (!isset($zipcodes[$zipcode][$day])) {
157 $zipcodes[$zipcode][$day] = [ $sessionId => $sessionId ];
158 } else {
159 $zipcodes[$zipcode][$day][$sessionId] = $sessionId;
160 }
161
162 //Get stop
163 $stop = $session->getStop();
164
165 //Set stop day
166 $day = $stop->diff((new \DateTime('now'))->setTime(0, 0, 0))->d + 1;
167
168 //Check if zipcode date is set
169 if (!isset($zipcodes[$zipcode][$day])) {
170 $zipcodes[$zipcode][$day] = [ $sessionId => $sessionId ];
171 } else {
172 $zipcodes[$zipcode][$day][$sessionId] = $sessionId;
173 }
174 }
175 }
176
177 //Process daily accuweather
178 if ($command == 'rapsysair:weather:daily' || $command == 'rapsysair:weather') {
179 //Fetch daily sessions to attribute
180 $types['daily'] = $this->doctrine->getRepository(Session::class)->findAllPendingDailyWeather();
181
182 //Iterate on each session
183 foreach($types['daily'] as $sessionId => $session) {
184 //Get zipcode
185 $zipcode = $session->getLocation()->getZipcode();
186
187 //Get start
188 $start = $session->getStart();
189
190 //Set start day
191 $day = 'daily';
192
193 //Check if zipcode is set
194 if (!isset($zipcodes[$zipcode])) {
195 $zipcodes[$zipcode] = [];
196 }
197
198 //Check if zipcode date is set
199 if (!isset($zipcodes[$zipcode][$day])) {
200 $zipcodes[$zipcode][$day] = [ $sessionId => $sessionId ];
201 } else {
202 $zipcodes[$zipcode][$day][$sessionId] = $sessionId;
203 }
204 }
205 }
206
207 //Init curl
208 $this->curl_init();
209
210 //Init data array
211 $data = [];
212
213 //Iterate on zipcodes
214 foreach($zipcodes as $zipcode => $days) {
215 //Iterate on days
216 foreach($days as $day => $null) {
217 //Try to load content from cache
218 if (!is_file($file = $tmpdir.'/'.$zipcode.'.'.$day.'.html') || stat($file)['ctime'] <= (time() - ($day == 'daily' ? 4 : 2)*3600) || ($content = file_get_contents($file)) === false) {
219 //Prevent timing detection
220 //XXX: from 0.1 to 5 seconds
221 usleep(rand(1,50) * 100000);
222
223 //Get content
224 //TODO: for daily we may load data for requested quarter of the day
225 $content = $this->curl_get($day == 'daily' ? $this->accuweather['daily'][$zipcode] : $this->accuweather['hourly'][$zipcode].$day);
226
227 //Store it
228 if (file_put_contents($tmpdir.'/'.$zipcode.'.'.$day.'.html', $content) === false) {
229 //Display error
230 echo 'Write to '.$tmpdir.'/'.$zipcode.'.'.$day.'.html failed'."\n";
231
232 //Exit with failure
233 exit(self::FAILURE);
234 }
235 }
236
237 //Parse string
238 $tidy->parseString($content, $this->config, 'utf8');
239
240 //Fix error buffer
241 //XXX: don't care about theses errors, tidy is here to fix...
242 #if (!empty($tidy->errorBuffer)) {
243 # var_dump($tidy->errorBuffer);
244 # die('Tidy errors');
245 #}
246
247 //Load simplexml
248 //XXX: trash all xmlns= broken tags
249 $sx = new \SimpleXMLElement(str_replace(['xmlns=', 'xlink:href='], ['xns=', 'href='], $tidy));
250
251 //Process daily
252 if ($day == 'daily') {
253 //Iterate on each link containing data
254 foreach($sx->xpath('//a[contains(@class,"daily-forecast-card")]') as $node) {
255 //Get date
256 $dsm = trim($node->div[0]->h2[0]->span[1]);
257
258 //Get temperature
259 $temperature = str_replace('Ā°', '', $node->div[0]->div[0]->span[0]);
260
261 //Get rainrisk
262 $rainrisk = trim(str_replace('%', '', $node->div[1]))/100;
263
264 //Store data
265 $data[$zipcode][$dsm]['daily'] = [
266 'temperature' => $temperature,
267 'rainrisk' => $rainrisk
268 ];
269 }
270 //Process hourly
271 } else {
272 //Iterate on each div containing data
273 #(string)$sx->xpath('//div[@class="hourly-card-nfl"]')[0]->attributes()->value
274 #/html/body/div[1]/div[5]/div[1]/div[1]/div[1]/div[1]/div[1]/div/h2/span[1]
275 foreach($sx->xpath('//div[@data-shared="false"]') as $node) {
276 //Get hour
277 $hour = trim(str_replace(' h', '', $node->div[0]->div[0]->div[0]->div[0]->div[0]->h2[0]));
278
279 //Compute dsm from day (1=d,2=d+1,3=d+2)
280 $dsm = (new \DateTime('+'.($day - 1).' day'))->format('d/m');
281
282 //Get temperature
283 $temperature = str_replace('Ā°', '', $node->div[0]->div[0]->div[0]->div[0]->div[1]);
284
285 //Get realfeel
286 $realfeel = trim(str_replace(['RealFeelĀ®', 'Ā°'], '', $node->div[0]->div[0]->div[0]->div[1]->div[0]->div[0]->div[0]));
287
288 //Get rainrisk
289 $rainrisk = floatval(str_replace('%', '', trim($node->div[0]->div[0]->div[0]->div[2]->div[0]))/100);
290
291 //Set rainfall to 0 (mm)
292 $rainfall = 0;
293
294 //Iterate on each entry
295 //TODO: wind and other infos are present in $node->div[1]->div[0]->div[1]->div[0]->p
296 foreach($node->div[1]->div[0]->div[1]->div[0]->p as $p) {
297 //Lookup for rain entry if present
298 if (in_array(trim($p), ['Rain', 'Pluie'])) {
299 //Get rainfall
300 $rainfall = floatval(str_replace(' mm', '', $p->span[0]));
301 }
302 }
303
304 //Store data
305 $data[$zipcode][$dsm][$hour] = [
306 'temperature' => $temperature,
307 'realfeel' => $realfeel,
308 'rainrisk' => $rainrisk,
309 'rainfall' => $rainfall
310 ];
311 }
312 }
313
314 //Cleanup
315 unset($sx);
316 }
317 }
318
319 //Iterate on types
320 foreach($types as $type => $sessions) {
321 //Iterate on each type
322 foreach($sessions as $sessionId => $session) {
323 //Get zipcode
324 $zipcode = $session->getLocation()->getZipcode();
325
326 //Get start
327 $start = $session->getStart();
328
329 //Daily type
330 if ($type == 'daily') {
331 //Set period
332 $period = [ $start ];
333 //Hourly type
334 } else {
335 //Get stop
336 $stop = $session->getStop();
337
338 //Compute period
339 $period = new \DatePeriod(
340 //Start from begin
341 $start,
342 //Iterate on each hour
343 new \DateInterval('PT1H'),
344 //End with begin + length
345 $stop
346 );
347 }
348
349 //Set meteo
350 $meteo = [
351 'rainfall' => null,
352 'rainrisk' => null,
353 'realfeel' => [],
354 'realfeelmin' => null,
355 'realfeelmax' => null,
356 'temperature' => [],
357 'temperaturemin' => null,
358 'temperaturemax' => null
359 ];
360
361 //Iterate on the period
362 foreach($period as $time) {
363 //Set dsm
364 $dsm = $time->format('d/m');
365
366 //Set hour
367 $hour = $type=='daily'?$type:$time->format('H');
368
369 //Check data availability
370 //XXX: sometimes startup delay causes weather data to be unavailable for session first hour
371 if (!isset($data[$zipcode][$dsm][$hour])) {
372 //Skip unavailable data
373 continue;
374 }
375
376 //Set info alias
377 $info = $data[$zipcode][$dsm][$hour];
378
379 //Check if rainrisk is higher
380 if ($meteo['rainrisk'] === null || $info['rainrisk'] > $meteo['rainrisk']) {
381 //Set highest rain risk
382 $meteo['rainrisk'] = floatval($info['rainrisk']);
383 }
384
385 //Check if rainfall is set
386 if (isset($info['rainfall'])) {
387 //Set rainfall sum
388 $meteo['rainfall'] += floatval($info['rainfall']);
389 }
390
391 //Add temperature
392 $meteo['temperature'][$hour] = $info['temperature'];
393
394 //Hourly type
395 if ($type != 'daily') {
396 //Check min temperature
397 if ($meteo['temperaturemin'] === null || $info['temperature'] < $meteo['temperaturemin']) {
398 $meteo['temperaturemin'] = floatval($info['temperature']);
399 }
400
401 //Check max temperature
402 if ($meteo['temperaturemax'] === null || $info['temperature'] > $meteo['temperaturemax']) {
403 $meteo['temperaturemax'] = floatval($info['temperature']);
404 }
405 }
406
407 //Check if realfeel is set
408 if (isset($info['realfeel'])) {
409 //Add realfeel
410 $meteo['realfeel'][$hour] = $info['realfeel'];
411
412 //Check min realfeel
413 if ($meteo['realfeelmin'] === null || $info['realfeel'] < $meteo['realfeelmin']) {
414 $meteo['realfeelmin'] = floatval($info['realfeel']);
415 }
416
417 //Check max realfeel
418 if ($meteo['realfeelmax'] === null || $info['realfeel'] > $meteo['realfeelmax']) {
419 $meteo['realfeelmax'] = floatval($info['realfeel']);
420 }
421 }
422 }
423
424 //Check if rainfall is set and differ
425 if ($session->getRainfall() !== $meteo['rainfall']) {
426 //Set rainfall
427 $session->setRainfall($meteo['rainfall']);
428 }
429
430 //Check if rainrisk differ
431 if ($session->getRainrisk() !== $meteo['rainrisk']) {
432 //Set rainrisk
433 $session->setRainrisk($meteo['rainrisk']);
434 }
435
436 //Check realfeel array
437 if ($meteo['realfeel'] !== []) {
438 //Compute realfeel
439 $realfeel = floatval(round(array_sum($meteo['realfeel'])/count($meteo['realfeel']),1));
440
441 //Check if realfeel differ
442 if ($session->getRealfeel() !== $realfeel) {
443 //Set average realfeel
444 $session->setRealfeel($realfeel);
445 }
446
447 //Check if realfeelmin differ
448 if ($session->getRealfeelmin() !== $meteo['realfeelmin']) {
449 //Set realfeelmin
450 $session->setRealfeelmin($meteo['realfeelmin']);
451 }
452
453 //Check if realfeelmax differ
454 if ($session->getRealfeelmax() !== $meteo['realfeelmax']) {
455 //Set realfeelmax
456 $session->setRealfeelmax($meteo['realfeelmax']);
457 }
458 }
459
460 //Check temperature array
461 if ($meteo['temperature'] !== []) {
462 //Compute temperature
463 $temperature = floatval(round(array_sum($meteo['temperature'])/count($meteo['temperature']),1));
464
465 //Check if temperature differ
466 if ($session->getTemperature() !== $temperature) {
467 //Set average temperature
468 $session->setTemperature($temperature);
469 }
470
471 //Check if temperaturemin differ
472 if ($session->getTemperaturemin() !== $meteo['temperaturemin']) {
473 //Set temperaturemin
474 $session->setTemperaturemin($meteo['temperaturemin']);
475 }
476
477 //Check if temperaturemax differ
478 if ($session->getTemperaturemax() !== $meteo['temperaturemax']) {
479 //Set temperaturemax
480 $session->setTemperaturemax($meteo['temperaturemax']);
481 }
482 }
483 }
484 }
485
486 //Flush to get the ids
487 $this->doctrine->getManager()->flush();
488
489 //Close curl handler
490 $this->curl_close();
491
492 //Return success
493 return self::SUCCESS;
494 }
495
496 /**
497 * Init curl handler
498 *
499 * @return bool|void Return success or exit
500 */
501 function curl_init() {
502 //Init curl
503 if (($this->ch = curl_init()) === false) {
504 //Display error
505 echo 'Curl init failed: '.curl_error($this->ch)."\n";
506 //Exit with failure
507 exit(self::FAILURE);
508 }
509
510 //Set curl options
511 if (
512 curl_setopt_array(
513 $this->ch,
514 [
515 //Force http2
516 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
517 //Set http headers
518 CURLOPT_HTTPHEADER => [
519 //XXX: it seems that you can disable akamai fucking protection with Pragma: akamai-x-cache-off
520 //XXX: see https://support.globaldots.com/hc/en-us/articles/115003996705-Akamai-Pragma-Headers-overview
521 #'Pragma: akamai-x-cache-off',
522 //XXX: working curl command
523 #curl --http2 --cookie file.jar --cookie-jar file.jar -v -i -k -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' -H 'Accept-Language: en-GB,en;q=0.9' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' -H 'Host: www.accuweather.com' -H 'Pragma: no-cache' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36' 'https://www.accuweather.com/'
524 //Set accept
525 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
526 //Set accept language
527 'Accept-Language: en-GB,en;q=0.9',
528 //Disable cache
529 'Cache-Control: no-cache',
530 //Keep connection alive
531 'Connection: keep-alive',
532 //Disable cache
533 'Pragma: no-cache',
534 //Force secure requests
535 'Upgrade-Insecure-Requests: 1',
536 //Set user agent
537 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
538 //Force akamai cookie
539 //XXX: seems to come from http request
540 'Cookie: AKA_A2=A',
541 ],
542 //Enable cookie
543 CURLOPT_COOKIEFILE => '',
544 //Disable location following
545 CURLOPT_FOLLOWLOCATION => false,
546 //Set url
547 #CURLOPT_URL => $url = 'https://www.accuweather.com/',
548 //Return headers too
549 CURLOPT_HEADER => true,
550 //Return content
551 CURLOPT_RETURNTRANSFER => true,
552
553 //XXX: debug
554 CURLINFO_HEADER_OUT => true
555 ]
556 ) === false
557 ) {
558 //Display error
559 echo 'Curl setopt array failed: '.curl_error($this->ch)."\n";
560 //Exit with failure
561 exit(self::FAILURE);
562 }
563
564 //Return success
565 return true;
566 }
567
568 /**
569 * Get url
570 *
571 * @return string|void Return url content or exit
572 */
573 function curl_get($url) {
574 //Set url to fetch
575 if (curl_setopt($this->ch, CURLOPT_URL, $url) === false) {
576 //Display error
577 echo 'Setopt for '.$url.' failed: '.curl_error($this->ch)."\n";
578
579 //Close curl handler
580 curl_close($this->ch);
581
582 //Exit with failure
583 exit(self::FAILURE);
584 }
585
586 //Check return status
587 if (($response = curl_exec($this->ch)) === false) {
588 //Display error
589 echo 'Get for '.$url.' failed: '.curl_error($this->ch)."\n";
590
591 //Display sent headers
592 var_dump(curl_getinfo($this->ch, CURLINFO_HEADER_OUT));
593
594 //Display response
595 var_dump($response);
596
597 //Close curl handler
598 curl_close($this->ch);
599
600 //Exit with failure
601 exit(self::FAILURE);
602 }
603
604 //Get header size
605 if (empty($hs = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE))) {
606 //Display error
607 echo 'Getinfo for '.$url.' failed: '.curl_error($this->ch)."\n";
608
609 //Display sent headers
610 var_dump(curl_getinfo($this->ch, CURLINFO_HEADER_OUT));
611
612 //Display response
613 var_dump($response);
614
615 //Close curl handler
616 curl_close($this->ch);
617
618 //Exit with failure
619 exit(self::FAILURE);
620 }
621
622 //Get header
623 if (empty($header = substr($response, 0, $hs))) {
624 //Display error
625 echo 'Header for '.$url.' empty: '.curl_error($this->ch)."\n";
626
627 //Display sent headers
628 var_dump(curl_getinfo($this->ch, CURLINFO_HEADER_OUT));
629
630 //Display response
631 var_dump($response);
632
633 //Close curl handler
634 curl_close($this->ch);
635
636 //Exit with failure
637 exit(self::FAILURE);
638 }
639
640 //Check request success
641 if (strlen($header) <= 10 || substr($header, 0, 10) !== 'HTTP/2 200') {
642 //Display error
643 echo 'Status for '.$url.' failed: '.curl_error($this->ch)."\n";
644
645 //Display sent headers
646 var_dump(curl_getinfo($this->ch, CURLINFO_HEADER_OUT));
647
648 //Display response
649 var_dump($header);
650
651 //Close curl handler
652 curl_close($this->ch);
653
654 //Exit with failure
655 exit(self::FAILURE);
656 }
657
658 //Return content
659 return substr($response, $hs);
660 }
661
662 /**
663 * Close curl handler
664 *
665 * @return bool Return success or failure
666 */
667 function curl_close() {
668 return curl_close($this->ch);
669 }
670 }