vendredi 21 juillet 2017

laravel loop stopping halfway throught?

I have a laravel command like this:

public function handle()
{
Film::truncate();
$arrayOfCinemaIds = [10565,7311,9434];
$startdate = strtotime("today");
$date = date("Y-m-d", $startdate);
$enddate = strtotime("+6 Days");
    while ($startdate < $enddate) { 
        foreach($arrayOfCinemaIds as $id){
            $data= file_get_contents('http://ift.tt/2ss18D7'.$id.'/?day='.$date);
            $data = json_decode($data);
            $find_id = Entity::where('api_key', $id)->get();
                foreach($find_id as $id_found) {
                    $entity_id = $id_found->id;
                        foreach($data->listings as $listing){
                            $title = $listing->title;
                            $time = implode(', ', $listing->times);
                            $film = new Film();
                            $film->title = $title;
                            $film->times = $time;
                            $film->entity_id = $entity_id;
                            $film->date = $date;
                            $film->save();
                        }
                        print_r($entity_id);
                }
        } 
        $startdate = strtotime("+1 Days", $startdate);
        $date = date("Y-m-d", $startdate);
        $this->info('Scraping cinema done, moving to next one');
    }
}

Which loops throught arrayof cinema, find in entity specific 'api_key' and loop throught each one to get the films.

So it should be like this:

For 6 days Loop throught cinemaid -> find api_key that matches id and for each data found save a film to relevant id. Which sort of works fine

but after doing the loop 3 times it crashes:

output is like this:

λ php artisan scrape:cinema
123Scraping cinema done, moving to next one
123Scraping cinema done, moving to next one
123Scraping cinema done, moving to next one
1



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire