Sarmen B. Sarmen B. - 9 months ago 61
PHP Question

best method to create a job that will sync data from an api to the database

I am dealing with the amazon mws api and its super painful. I want to create a cron that will at a later time go out and fetch a ton of data from the api and store it locally on the database. What is the best method of doing this since it will be dealing with a ton of data not really sure if i would need to create a job, a task or whatnot without it crashing or timing out. I'm using laravel 5.3

Answer Source

I think the best way to solve this problem is creating jobs.In most cases, this well gets you around PHP's memory limit, since the CLI limit is usually higher than the limit for HTTP requests.

And If you don't want to timeout your worker then you can listen your queue as:

php artisan queue:work --timeout=0

Now the question is how you will dispatch the job dispatch(new SomeProcess()); using cron.

So the answer is using Laravel's Task Scheduling as:

$schedule->call(function () {
    dispatch(new SomeProcess());