You don’t need to get data from external API in client side and post them again to your server.
PHP can send get request and receive response without jQuery.
You can write php script to get product price list from external API like the following:
$url = "https://www.notimportant/etc/";
$header = ['GUID' => 'something']
echo "Sending request to API server...\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_HEADER, $header);
$response = curl_exec($ch);
echo "Received response\n";
curl_close($ch);
$data = json_decode($response);
echo "Product count: " . count($data) . "\n";
echo "Saving products to database...";
foreach($data as $productInfo) {
save_data($productInfo); // you need to implement save_data
}
echo "Products saved. Exiting"\n;
exit(0);
If you want to know how to write string (JSON response in this case) to file, refer to this: How to put the a string into a text file in PHP?
If you want to know how to execute MySQL query using prepared statements, refer to this: How can I prevent SQL injection in PHP?
If you want to know how to send https request with custom header, refer to this post: Send GET HTTPS request with custom headers PHP
If you want to know how to execute a php script on a regular basis using crontab, refer to this post: Running PHP file using crontab
(Don’t worry, they’re all stackoverflow posts)
I would use something elegant, let’s say to use 500 queries in a single transaction (and make the entire update in just 80 steps instead of a full 40,000 simple queries), but not sure how to set everything right.
Transaction won’t improve performance, transaction is never meant for performance but for data integrity. Making 40,000 simple queries and executing them all at once (or one by one, if you say so) is the best option here.
solved How to save a blob (AJAX response) into a named file (JSON type) into my server NOT in user computer [closed]