How to run one php ‘update’ script after another?

I have a simple php ‘update’ script that connects to an API, retrieves data and inserts it into a mysql table.

I need to be able to do this for several thousand products, one after the other each day.

I’ve been using JavaScript and ajax to call the php script and upon a successful response run the script for the next product in sequence.

It works but is there a better way to achieve this?