]> Raphaƫl G. Git Repositories - airbundle/blob - Command/WeatherCommand.php
ee339810c65f721e0ee5b302e5f360153441dc24
[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 = str_replace('%', '', trim($node->div[2]))/100;
263 $rainrisk = trim(str_replace('%', '', $node->div[1]))/100;
264
265 //Store data
266 $data[$zipcode][$dsm]['daily'] = [
267 'temperature' => $temperature,
268 'rainrisk' => $rainrisk
269 ];
270 }
271 //Process hourly
272 } else {
273 //Iterate on each div containing data
274 #(string)$sx->xpath('//div[@class="hourly-card-nfl"]')[0]->attributes()->value
275 #/html/body/div[1]/div[5]/div[1]/div[1]/div[1]/div[1]/div[1]/div/h2/span[1]
276 foreach($sx->xpath('//div[@data-shared="false"]') as $node) {
277 //Get hour
278 $hour = trim(str_replace(' h', '', $node->div[0]->div[0]->div[0]->div[0]->div[0]->h2[0]));
279
280 //Compute dsm from day (1=d,2=d+1,3=d+2)
281 $dsm = (new \DateTime('+'.($day - 1).' day'))->format('d/m');
282
283 //Get temperature
284 $temperature = str_replace('Ā°', '', $node->div[0]->div[0]->div[0]->div[0]->div[1]);
285
286 //Get realfeel
287 $realfeel = trim(str_replace(['RealFeelĀ®', 'Ā°'], '', $node->div[0]->div[0]->div[0]->div[1]->div[0]->div[0]->div[0]));
288
289 //Get rainrisk
290 $rainrisk = floatval(str_replace('%', '', trim($node->div[0]->div[0]->div[0]->div[2]->div[0]))/100);
291
292 //Set rainfall to 0 (mm)
293 $rainfall = 0;
294
295 //Iterate on each entry
296 //TODO: wind and other infos are present in $node->div[1]->div[0]->div[1]->div[0]->p
297 #foreach($node->div[1]->div[0]->div[1]->div[1]->p as $p) {
298 foreach($node->div[1]->div[0]->div[1]->div[0]->p as $p) {
299 //Lookup for rain entry if present
300 if (in_array(trim($p), ['Rain', 'Pluie'])) {
301 //Get rainfall
302 $rainfall = floatval(str_replace(' mm', '', $p->span[0]));
303 }
304 }
305
306 //Store data
307 $data[$zipcode][$dsm][$hour] = [
308 'temperature' => $temperature,
309 'realfeel' => $realfeel,
310 'rainrisk' => $rainrisk,
311 'rainfall' => $rainfall
312 ];
313 }
314 }
315
316 //Cleanup
317 unset($sx);
318 }
319 }
320
321 //Iterate on types
322 foreach($types as $type => $sessions) {
323 //Iterate on each type
324 foreach($sessions as $sessionId => $session) {
325 //Get zipcode
326 $zipcode = $session->getLocation()->getZipcode();
327
328 //Get start
329 $start = $session->getStart();
330
331 //Daily type
332 if ($type == 'daily') {
333 //Set period
334 $period = [ $start ];
335 //Hourly type
336 } else {
337 //Get stop
338 $stop = $session->getStop();
339
340 //Compute period
341 $period = new \DatePeriod(
342 //Start from begin
343 $start,
344 //Iterate on each hour
345 new \DateInterval('PT1H'),
346 //End with begin + length
347 $stop
348 );
349 }
350
351 //Set meteo
352 $meteo = [
353 'rainfall' => null,
354 'rainrisk' => null,
355 'realfeel' => [],
356 'realfeelmin' => null,
357 'realfeelmax' => null,
358 'temperature' => [],
359 'temperaturemin' => null,
360 'temperaturemax' => null
361 ];
362
363 //Iterate on the period
364 foreach($period as $time) {
365 //Set dsm
366 $dsm = $time->format('d/m');
367
368 //Set hour
369 $hour = $type=='daily'?$type:$time->format('H');
370
371 //Check data availability
372 //XXX: sometimes startup delay causes weather data to be unavailable for session first hour
373 if (!isset($data[$zipcode][$dsm][$hour])) {
374 //Skip unavailable data
375 continue;
376 }
377
378 //Set info alias
379 $info = $data[$zipcode][$dsm][$hour];
380
381 //Check if rainrisk is higher
382 if ($meteo['rainrisk'] === null || $info['rainrisk'] > $meteo['rainrisk']) {
383 //Set highest rain risk
384 $meteo['rainrisk'] = floatval($info['rainrisk']);
385 }
386
387 //Check if rainfall is set
388 if (isset($info['rainfall'])) {
389 //Set rainfall sum
390 $meteo['rainfall'] += floatval($info['rainfall']);
391 }
392
393 //Add temperature
394 $meteo['temperature'][$hour] = $info['temperature'];
395
396 //Hourly type
397 if ($type != 'daily') {
398 //Check min temperature
399 if ($meteo['temperaturemin'] === null || $info['temperature'] < $meteo['temperaturemin']) {
400 $meteo['temperaturemin'] = floatval($info['temperature']);
401 }
402
403 //Check max temperature
404 if ($meteo['temperaturemax'] === null || $info['temperature'] > $meteo['temperaturemax']) {
405 $meteo['temperaturemax'] = floatval($info['temperature']);
406 }
407 }
408
409 //Check if realfeel is set
410 if (isset($info['realfeel'])) {
411 //Add realfeel
412 $meteo['realfeel'][$hour] = $info['realfeel'];
413
414 //Check min realfeel
415 if ($meteo['realfeelmin'] === null || $info['realfeel'] < $meteo['realfeelmin']) {
416 $meteo['realfeelmin'] = floatval($info['realfeel']);
417 }
418
419 //Check max realfeel
420 if ($meteo['realfeelmax'] === null || $info['realfeel'] > $meteo['realfeelmax']) {
421 $meteo['realfeelmax'] = floatval($info['realfeel']);
422 }
423 }
424 }
425
426 //Check if rainfall is set and differ
427 if ($session->getRainfall() !== $meteo['rainfall']) {
428 //Set rainfall
429 $session->setRainfall($meteo['rainfall']);
430 }
431
432 //Check if rainrisk differ
433 if ($session->getRainrisk() !== $meteo['rainrisk']) {
434 //Set rainrisk
435 $session->setRainrisk($meteo['rainrisk']);
436 }
437
438 //Check realfeel array
439 if ($meteo['realfeel'] !== []) {
440 //Compute realfeel
441 $realfeel = floatval(round(array_sum($meteo['realfeel'])/count($meteo['realfeel']),1));
442
443 //Check if realfeel differ
444 if ($session->getRealfeel() !== $realfeel) {
445 //Set average realfeel
446 #$meteo['realfeel'] = array_sum($meteo['realfeel'])/count($meteo['realfeel']);
447 $session->setRealfeel($realfeel);
448 }
449
450 //Check if realfeelmin differ
451 if ($session->getRealfeelmin() !== $meteo['realfeelmin']) {
452 //Set realfeelmin
453 $session->setRealfeelmin($meteo['realfeelmin']);
454 }
455
456 //Check if realfeelmax differ
457 if ($session->getRealfeelmax() !== $meteo['realfeelmax']) {
458 //Set realfeelmax
459 $session->setRealfeelmax($meteo['realfeelmax']);
460 }
461 }
462
463 //Check temperature array
464 if ($meteo['temperature'] !== []) {
465 //Compute temperature
466 $temperature = floatval(round(array_sum($meteo['temperature'])/count($meteo['temperature']),1));
467
468 //Check if temperature differ
469 if ($session->getTemperature() !== $temperature) {
470 //Set average temperature
471 #$meteo['temperature'] = array_sum($meteo['temperature'])/count($meteo['temperature']);
472 $session->setTemperature($temperature);
473 }
474
475 //Check if temperaturemin differ
476 if ($session->getTemperaturemin() !== $meteo['temperaturemin']) {
477 //Set temperaturemin
478 $session->setTemperaturemin($meteo['temperaturemin']);
479 }
480
481 //Check if temperaturemax differ
482 if ($session->getTemperaturemax() !== $meteo['temperaturemax']) {
483 //Set temperaturemax
484 $session->setTemperaturemax($meteo['temperaturemax']);
485 }
486 }
487 }
488 }
489
490 //Flush to get the ids
491 $this->doctrine->getManager()->flush();
492
493 //Close curl handler
494 $this->curl_close();
495
496 //Return success
497 return self::SUCCESS;
498 }
499
500 /**
501 * Init curl handler
502 *
503 * @return bool|void Return success or exit
504 */
505 function curl_init() {
506 //Init curl
507 if (($this->ch = curl_init()) === false) {
508 //Display error
509 echo 'Curl init failed: '.curl_error($this->ch)."\n";
510 //Exit with failure
511 exit(self::FAILURE);
512 }
513
514 //Set curl options
515 if (
516 curl_setopt_array(
517 $this->ch,
518 [
519 //Force http2
520 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
521 //Set http headers
522 CURLOPT_HTTPHEADER => [
523 //XXX: it seems that you can disable akamai fucking protection with Pragma: akamai-x-cache-off
524 //XXX: see https://support.globaldots.com/hc/en-us/articles/115003996705-Akamai-Pragma-Headers-overview
525 #'Pragma: akamai-x-cache-off',
526 //XXX: working curl command
527 #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/'
528 //Set accept
529 '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',
530 //Set accept language
531 'Accept-Language: en-GB,en;q=0.9',
532 //Disable cache
533 'Cache-Control: no-cache',
534 //Keep connection alive
535 'Connection: keep-alive',
536 //Disable cache
537 'Pragma: no-cache',
538 //Force secure requests
539 'Upgrade-Insecure-Requests: 1',
540 //Set user agent
541 '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',
542 //Force akamai cookie
543 //XXX: seems to come from http request
544 'Cookie: AKA_A2=A',
545 ],
546 //Enable cookie
547 CURLOPT_COOKIEFILE => '',
548 //Disable location following
549 CURLOPT_FOLLOWLOCATION => false,
550 //Set url
551 #CURLOPT_URL => $url = 'https://www.accuweather.com/',
552 //Return headers too
553 CURLOPT_HEADER => true,
554 //Return content
555 CURLOPT_RETURNTRANSFER => true,
556
557 //XXX: debug
558 CURLINFO_HEADER_OUT => true
559 ]
560 ) === false
561 ) {
562 //Display error
563 echo 'Curl setopt array failed: '.curl_error($this->ch)."\n";
564 //Exit with failure
565 exit(self::FAILURE);
566 }
567
568 //Return success
569 return true;
570 }
571
572 /**
573 * Get url
574 *
575 * @return string|void Return url content or exit
576 */
577 function curl_get($url) {
578 //Set url to fetch
579 if (curl_setopt($this->ch, CURLOPT_URL, $url) === false) {
580 //Display error
581 echo 'Setopt for '.$url.' failed: '.curl_error($this->ch)."\n";
582
583 //Close curl handler
584 curl_close($this->ch);
585
586 //Exit with failure
587 exit(self::FAILURE);
588 }
589
590 //Check return status
591 if (($response = curl_exec($this->ch)) === false) {
592 //Display error
593 echo 'Get for '.$url.' failed: '.curl_error($this->ch)."\n";
594
595 //Display sent headers
596 var_dump(curl_getinfo($this->ch, CURLINFO_HEADER_OUT));
597
598 //Display response
599 var_dump($response);
600
601 //Close curl handler
602 curl_close($this->ch);
603
604 //Exit with failure
605 exit(self::FAILURE);
606 }
607
608 //Get header size
609 if (empty($hs = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE))) {
610 //Display error
611 echo 'Getinfo for '.$url.' failed: '.curl_error($this->ch)."\n";
612
613 //Display sent headers
614 var_dump(curl_getinfo($this->ch, CURLINFO_HEADER_OUT));
615
616 //Display response
617 var_dump($response);
618
619 //Close curl handler
620 curl_close($this->ch);
621
622 //Exit with failure
623 exit(self::FAILURE);
624 }
625
626 //Get header
627 if (empty($header = substr($response, 0, $hs))) {
628 //Display error
629 echo 'Header for '.$url.' empty: '.curl_error($this->ch)."\n";
630
631 //Display sent headers
632 var_dump(curl_getinfo($this->ch, CURLINFO_HEADER_OUT));
633
634 //Display response
635 var_dump($response);
636
637 //Close curl handler
638 curl_close($this->ch);
639
640 //Exit with failure
641 exit(self::FAILURE);
642 }
643
644 //Check request success
645 if (strlen($header) <= 10 || substr($header, 0, 10) !== 'HTTP/2 200') {
646 //Display error
647 echo 'Status for '.$url.' failed: '.curl_error($this->ch)."\n";
648
649 //Display sent headers
650 var_dump(curl_getinfo($this->ch, CURLINFO_HEADER_OUT));
651
652 //Display response
653 var_dump($header);
654
655 //Close curl handler
656 curl_close($this->ch);
657
658 //Exit with failure
659 exit(self::FAILURE);
660 }
661
662 //Return content
663 return substr($response, $hs);
664 }
665
666 /**
667 * Close curl handler
668 *
669 * @return bool Return success or failure
670 */
671 function curl_close() {
672 return curl_close($this->ch);
673 }
674 }