S
S
Sergey2018-09-06 16:20:29
PHP
Sergey, 2018-09-06 16:20:29

How can I change the script to run it with CRON?

Good afternoon, I'm working with cron for the first time, when I start it from the hosting control panel with the command

GET xn--80acq4ak0e.xn--80aaatxoydf6aq7i.xn--p1ai/script.php

I get an error
<b>Parse error</b>:  syntax error, unexpected '['  on line <b>6</b>

Can you tell me what needs to be changed, that the script has earned with the help of cron? without cron, just when you go to the page everything works
<?php 
  header('Content-Type: application/json; charset=utf-8');

  $ch = curl_init();

  $arr = [];


  $options = array(CURLOPT_URL => 'https://flamp.ru/api/2.0/filials/70000001006315053/reviews?limit=5',
                  CURLOPT_RETURNTRANSFER => true,
          CURLOPT_FOLLOWLOCATION => true,
          CURLOPT_HTTPHEADER => array('Authorization: Bearer 2b93f266f6a4df2bb7a196bb76dca60181ea3b37')                 
                  );
    curl_setopt_array($ch, $options);

  $rev5 = curl_exec($ch);

  $arr5 = json_decode($rev5)->reviews;
  foreach ($arr5 as $rev) {
    $user_url = $rev->user;
    curl_setopt($ch, CURLOPT_URL, $user_url);
    $user = curl_exec($ch);
    $rev->user = json_decode($user)->user;


    $comments_lnk = $rev->comments;
    curl_setopt($ch, CURLOPT_URL, $comments_lnk);
    $comments = curl_exec($ch);
    $rev->comments = json_decode($comments)->comments;


    $project_lnk = $rev->project;
    curl_setopt($ch, CURLOPT_URL, $project_lnk);
    $project = curl_exec($ch);
    $rev->project = json_decode($project)->project;


    $filial_lnk = $rev->filial;
    curl_setopt($ch, CURLOPT_URL, $filial_lnk);
    $filial = curl_exec($ch);
    $rev->filial = json_decode($filial)->filial;

    
    $photos_lnk = $rev->photos;
    if(gettype($photos_lnk) == 'string') {
      curl_setopt($ch, CURLOPT_URL, $photos_lnk);
      $photos = curl_exec($ch);
      $rev->photos = json_decode($photos)->photos;
    }



    $photo_lnk = $rev->photo;
    curl_setopt($ch, CURLOPT_URL, $photo_lnk);
    $photo = curl_exec($ch);
    $rev->photo = json_decode($photo)->photo;


    $arr[] = $rev;
  }


  while(true){
    if( isset( json_decode($rev5)->next_link ) ){
      $next = json_decode($rev5)->next_link;


      curl_setopt($ch, CURLOPT_URL, $next);
      $rev5 = curl_exec($ch);
      

      $arr5 = json_decode($rev5)->reviews;
      foreach ($arr5 as $rev) {
        $user_url = $rev->user;
        curl_setopt($ch, CURLOPT_URL, $user_url);
        $user = curl_exec($ch);

        $comments_lnk = $rev->comments;
        curl_setopt($ch, CURLOPT_URL, $comments_lnk);
        $comments = curl_exec($ch);


        $photos_lnk = $rev->photos;

        if(gettype($photos_lnk) == 'string') {
          curl_setopt($ch, CURLOPT_URL, $photos_lnk);
          $photos = curl_exec($ch);
          $rev->photos = json_decode($photos)->photos;
        }
        
        $photo_lnk = $rev->photo;
        curl_setopt($ch, CURLOPT_URL, $photo_lnk);
        $photo = curl_exec($ch);
        $rev->photo = json_decode($photo)->photo;
        
        
        $rev->comments = json_decode($comments)->comments;
        $rev->user = json_decode($user)->user;
        $arr[] = $rev;
      }


      
    } else {
      break;
    }
  }


  file_put_contents('data.json', json_encode($arr));
  file_put_contents('test.json', json_encode($arr));

?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Adamos, 2018-09-06
@1Sergey1

You don't have Timeweb, do you? They stubbornly hold on to the PHP 5.3 cli.
You need to force a newer version of PHP to run (for example, by writing a sh-script and writing it to cron).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question