Toni Perić
Toni Perić

Reputation: 512

Laravel script stops running after some time

I have this php script that runs for quite a while but after some time (due to browser limit when it stops loading the page) it stops with executing the code.

Basically what it does is fetch 10000 articles using an API and store them one-by-one in my own DB. After looping roughly 1200+ articles, the Google Chrome spinning/loading icon stops and all I get back in return is a blank page. When I check the DB I can see the results in the DB, but however the script didn't loop through all the articles as it should and it stopped.

I know running from CLI would remove the default browser-time-limit when it stops loading, but I don't know how to make a call to a certain controller method in Laravel from command line?

Upvotes: 1

Views: 1870

Answers (3)

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87779

Since you are in fact seeding a database, a quick and dirty way is to use db:seed to do it for you:

class MyTableSeeder extends Seeder {

    public function run()
    {

            // Do whatever you need to

    }

}

Enable it on DatabaseSeeder:

class DatabaseSeeder extends Seeder {

    public function run()
    {
        $this->call('MyTableSeeder');
    }

}

And execute it:

php artisan db:seed

A much better way is to create an Artisan Command. Here's another answer I wrote to teach how to create it: Select all rows with a date of right now

Upvotes: 1

Dkok
Dkok

Reputation: 312

Make an Artisan command. See the docs at http://laravel.com/docs/commands

Upvotes: 2

Abdulaziz
Abdulaziz

Reputation: 2211

  1. remove timeout limit from the web server(mostly from the config file)
  2. Use set_time_limit(0) to force PHP to execute your code for unlimited amount of time.

Upvotes: 0

Related Questions