Reputation: 512
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
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
Reputation: 312
Make an Artisan command. See the docs at http://laravel.com/docs/commands
Upvotes: 2
Reputation: 2211
set_time_limit(0)
to force PHP to execute your code for unlimited amount of time.Upvotes: 0