Ways to load admin-ajax faster without initializing all plugins?

by brandNewWPUser   Last Updated November 01, 2017 06:08 AM

I'm facing a problem with wp ajax performance. I'm initializing an ajax call from my javascript side but the response takes 3-5 secs to come back. I understand that admin ajax call has to load the whole wp core and that would definitely be a performance hit for us.

Is there a way to still use the admin ajax call, but without loading all plugins? Essentially in my php api, I'm only using some values from wp-config. Or is there any better ajax suggestions given my use case? Is it possible to use regular rest API(without going through admin-ajax) but could still use the values from wp-config?

Here is my js code(ajax.js):

jQuery.ajax({
        url: ajax_object.ajax_url,
        data: {
            action: 'geo_ip_api'
       },

        type: 'POST',
        success: function (output) {
            console.log(output);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            console.log(xhr.status);
            console.log(xhr.responseText);
            console.log(thrownError);
        }
    });

Here is my php api(api.php):

function geo_ip_api(){
global $bannerRequiredRegions;
global $ipBlackList;
$isInEU = 'null';
$ipAddress = get_ip_address();
if(!in_array(strtolower($ipAddress), array_map('strtolower', $ipBlackList)))
{
    try
    {
        require_once 'HTTP/Request2.php';
        /* retrieving values from wp-config */
        $api_url = GEO_API_URL;


        $request = new Http_Request2($api_url);
        $url = $request->getUrl();

        //sending HTTP request logic here. No dependency on wordpress
    }
    catch (Exception $ex)
    {
        //TODO: put log here
    }
}

echo $isInEU;

}

Any help appreciated! Thanks in advance. I've searched lots of post and none of those could answer my question.



Related Questions




Having trouble filtering Wordpress REST API JSON

Updated October 24, 2017 14:08 PM