SEO Explorer Blog:
Try us:

PHP SEO API – Using PHP to get SEO data

PHP Magnifying glass

PHP was invented in 1994 for web applications, it’s very similar to C and C++, and it’s ranked #7 as in popularity of development language.

It is used by sites such as Facebook, Slack and us, of course. Since it’s similar to C/C++, it was easy to learn and use.

We have an SEO API PHP, that supports any language that can make a web request, PHP included. We have developed some of our apps using PHP, and in this post, I will cover how to use our SEO API using PHP.

SEO API Structure

Any request is composed of four parts:

  1. API Key
  2. Request type
  3. Domain or Keyword
  4. Optional data

The reply is JSON based.

API Key

You can get the key for internal use when you subscribe to one of our plans, and if you just want to test the API, you can use the user demo, keep in mind it’s limited to the domain “ebay.com” and the keyword “seo”.

Request type

We support over 20 types of requests, for example, backlink information, keyword search volume, similar keywords, URL Classification and more.

You can see the entire list of SEO API Calls.

Domain or Keyword

Domain or keyword is used to specify the subject we want to get data on, so if we want to get links of eBay, the data would be “ebay.com”

Optional data

Optional data can be used to set the range of the request, add additional filters, and it’s specific to each request.

Reply

The reply is JSON based, and it can be a single set of replies or an array of replies, it’s specific to each request.

PHP Request

Before making a request to the PHP SEO API, we need to understand how to make a web request with PHP.

An easy way is to use libcurl which is part of PHP (I’m referring to version 7.2 and above, any version before is deprecated)

There are two ways to use libcurl:

Libcurl blocked request

A blocked request means that the call will not finish until one of the conditions was satisfied:

  • Timeout occurred
  • Connection error
  • All data received successfully

A blocked call means that a call can “wait” for a long time in case of an error or bad connection, or until a timeout was triggered.

In case the application needs to do more things in the background, that can cause an issue, especially that PHP doesn’t have built-in multithreading support.

An example request would be:

//The request
$Request = 'https://www.google.com';

//Make the request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);

In this example we build the request, which is Google, then we init libcurl and set it to return the value to our variable (instead of writing it to output), and then we get the data.

This example doesn’t check if there was an error.

Libcurl async request

An async request means that while the request is made, the code can continue to run. Since PHP doesn’t have multithreading, it’s possible to simulate multithreading by making multiple requests in parallel that run in the background.

Since this is not a PHP guide, this technique will not be covered here.

Making a call to the SEO API

We will use PHP to make a call to the SEO API to get the domain score of ebay.com:

//The request
$Request = 'https://app.seo-explorer.io/api.php?token=';
$Request .= 'demo';
$Request .= '&apitype=domaininformation&domain=' . urlencode('ebay.com');

//Check the links
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);

//Parse the result
$result = json_decode($output);
if (isset($result->domainscore))
            echo 'Domain Score: ' . $result->domainscore;

We made a request to the API using the demo token, we parsed the result and printed the domain score.

Parsing array reply

Another case is when the returned data is an array, we will use PHP to make a call to the SEO API to print the referring domain’s classification:

//Get another data
$Request = 'https://app.seo-explorer.io/api.php?token=demo';
$Request .= '&apitype=domainclassification&domain=' . urlencode('ebay.com');

//Get the data
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);

//Parse the result
$result = json_decode($output);

//Iterate the result
if (isset($result->result))
    for ($i = 0;
         $i < count($result->result);
         ++$i)
        echo $result->result[$i]->classification . "\n";

Summary

Using our SEO API with PHP is easy, with more than 20 API types, you can try it now with the demo user or a full subscription.

BTW, we also offer a token trial if you need to test before your buy, contact us.

1 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Share via
Copy link
Powered by Social Snap