0

I have a curl request on an api with pagination and now I'd like to execute my php script several times so that I don't have to start it manually with a different pagenumber

$endpoint = 'https://xxx.weclapp.com/webapp/api/v1/';
$api_token = 'xxx';
$articlePerPage = 100;
$currentPage = 1;
$amountOfArticles = "different curl get request (approx 1100)"
$amountOfPages = ceil($amountOfArticles / $articlePerPage);
$header = array();
$header[] = 'Content-type: application/json';
$header[] = 'AuthenticationToken:'.$api_token;
curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_URL,$endpoint.'article/?page='.$currentPage.'&pageSize='.$articlePerPage);
curl_setopt($curl, CURLOPT_HTTPGET, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$JSON = curl_exec($curl);
$result = json_decode($JSON);

I tried to put it in a while loop

while ($currentPage <= $amountOfPages) : ...; endwhile;

but unfortunately there are to much products respectively it takes to long so my server won't finish all these calls and I get a 504

At the moment I start this script manually 12 times each time with a different $currentPage number. My idea is to let the server finish the script, then restart it with $currentPage++ but I don't have any clue how to do that.

I've read the solution on this topic 9798438 with the bin/bash script but then I can't change my $currentPage variable

Does anyone has any idea how I could manage what I'm trying to do?

Thank you very much, I'd appreciate any help

Alex

2
  • i guess your 504 loop was completely unoptimized? you probably did NOT use compression, did NOT re-use tcp connections, did NOT re-use curl handles, and did NOT use curl_multi/multiprocessing... ? Commented Mar 10, 2018 at 10:27
  • Thank you, I will look into your suggestions Commented Mar 10, 2018 at 10:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.