0
votes

I wrote a custom WordPress plugin that creates a cron job that once a day calls the StoreRocket API to grab all the locations. Since there are more than 2000 entries, and their API has a 60 api call per min rate limit each get all location only gives me 15 entries per page, I had to call the api almost 150 times with a 1 second sleep(1) after each API call.

while ( $current_page <= $page_count ) { 
    set_time_limit(0);
    $current_page_url = $storerocket_api_url . "?page=" . $current_page;
    $storerocket_get_request = wp_remote_get( $current_page_url, $request_args );   
    if ( is_wp_error( $storerocket_post_request ) ) {
        $log =  "ERROR\n" ;
        $log .= $storerocket_post_request->get_error_message();
        storerocket_log($log);
    }         
    $get_response_body = $storerocket_get_request['body'];
    $storerocket_location_data = json_decode( $get_response_body );            
    $current_page = $storerocket_location_data->meta->current_page;

    array_push( $storerocket_location_array, $storerocket_location_data->data );

    storerocket_log( "page " . $current_page );            
    sleep(1);
    $current_page++;
}

It all works on my local testing. But when I deployed the plugin to the live server hosted at SiteGround, the cron job stopped at exactly 1 mimute although in the the php_ini the set_time_limit is set at 120. I check the error log, it gives a "Timeout waiting for output from CGI script" at exactly 1 minute after the cron job is called. After some research, I found the Apache Timeout on Siteground is 60 seconds and cannot be changed.

Is there a way to bypass the Apache timeout in code?