Integrate the Real-Time Category API in PHP
Your PHP application needs to decide what to do with a submitted website: enrich a signup, review an ad placement, or apply a content-filtering policy. By the end of this guide, you can send a live categorization request to Klazify, inspect the returned categories and confidence values, and turn the result into a decision your pipeline can audit.
Why use live categorization in a PHP pipeline?
Documentation describes Klazify’s domain intelligence services. For a PHP application, the real-time categorization endpoint provides a focused path from a submitted URL to categories, confidence values, a domain URL, and an update timestamp.
This is useful when a category affects a decision immediately. For example, an ad-placement audit can send a publisher URL for analysis, map the returned category to an internal policy, and hold the placement for review when the result is unclear. A signup workflow can use the same result to add context to a lead without requiring a sales representative to inspect every website manually.
Klazify analyzes website content rather than relying only on metadata, supports websites in multiple languages, and uses a hierarchical categorization system that includes IAB taxonomy mapping. Those features are useful when a site’s name alone does not reveal its subject, or when an advertising team needs to translate categories into an industry-standard vocabulary.
Every call to the real-time endpoint is live. That makes it a fit for workflows where a fresh classification matters, but it also means your application should plan for network latency, unavailable sites, and the choice between a fresh request and a cached result. Classification can inform a filtering or compliance workflow; it should not be treated as a guarantee that a site is safe or compliant.
Send a live request
Create an account, obtain an API key, and replace YOUR_API_KEY in the request below. The endpoint accepts a JSON object containing url, with the key supplied as a Bearer token. There is no need to send a refresh parameter: the request is already live.
curl -X POST "https://www.klazify.com/api/real_time_categorization" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://cbsnews.com"}'
Keep the API key on the server, not in browser-delivered JavaScript or a committed source file. In production, load it from your deployment’s secret management system or an environment variable. The request body should contain the URL your application actually needs to classify.
Call the endpoint from PHP
The following script uses PHP’s cURL extension. It accepts the website URL as a command-line argument and reads the key from KLAZIFY_API_KEY. It checks for transport and HTTP errors before decoding the response, then walks the JSON to show the fields relevant to categorization without assuming a particular nesting structure.
<?php
$url = $argv[1] ?? '';
$apiKey = getenv('KLAZIFY_API_KEY');
if ($url === '' || !$apiKey) {
fwrite(STDERR, "Provide a URL and set KLAZIFY_API_KEY.\n");
exit(1);
}
$handle = curl_init(
'https://www.klazify.com/api/real_time_categorization'
);
curl_setopt_array($handle, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode(
['url' => $url],
JSON_THROW_ON_ERROR
),
]);
$body = curl_exec($handle);
if ($body === false) {
$error = curl_error($handle);
curl_close($handle);
fwrite(STDERR, "Request failed: " . $error . "\n");
exit(1);
}
$status = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
if ($status < 200 || $status >= 300) {
fwrite(STDERR, "HTTP error: " . $status . "\n");
exit(1);
}
try {
$data = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $error) {
fwrite(STDERR, "Invalid JSON response.\n");
exit(1);
}
function showCategorizationFields($value): void
{
if (!is_array($value)) {
return;
}
$wanted = ['categories', 'confidence', 'domain_url', 'updated_at'];
foreach ($value as $key => $item) {
if (is_string($key) && in_array($key, $wanted, true)) {
echo $key . ': ' . json_encode(
$item,
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
) . PHP_EOL;
}
showCategorizationFields($item);
}
}
showCategorizationFields($data);
Pass the URL as the first argument when running the script. The output is intended for inspection: before making a policy decision, validate the actual response structure your application receives and handle missing fields explicitly. A successful HTTP response alone should not be interpreted as permission to allow or block a site.
Read the same fields in Python
If your enrichment pipeline has Python workers alongside a PHP application, the same request can be made with the standard library. This version also walks the decoded JSON so it can display the relevant fields without depending on an unverified response nesting.
import json
import os
import sys
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
if len(sys.argv) != 2:
sys.exit("Provide a URL as the first argument.")
api_key = os.environ.get("KLAZIFY_API_KEY")
if not api_key:
sys.exit("Set KLAZIFY_API_KEY.")
request = Request(
"https://www.klazify.com/api/real_time_categorization",
data=json.dumps({"url": sys.argv[1]}).encode("utf-8"),
headers={
"Authorization": "Bearer " + api_key,
"Content-Type": "application/json",
},
method="POST",
)
try:
with urlopen(request) as response:
data = json.load(response)
except HTTPError as error:
sys.exit("HTTP error: " + str(error.code))
except URLError as error:
sys.exit("Request failed: " + str(error.reason))
except (ValueError, UnicodeDecodeError):
sys.exit("Invalid JSON response.")
wanted = {"categories", "confidence", "domain_url", "updated_at"}
def show_fields(value):
if isinstance(value, dict):
for key, item in value.items():
if key in wanted:
print(key + ":", json.dumps(item, ensure_ascii=False))
show_fields(item)
elif isinstance(value, list):
for item in value:
show_fields(item)
show_fields(data)
For both implementations, distinguish a network or parsing failure from a valid response that does not contain a usable category. Your application can retry a transient failure, while an unknown classification should follow a separately defined review or fallback policy.
Understand categories and confidence
The real-time endpoint returns categories with confidence, along with domain_url and updated_at. Use the domain URL to associate the result with the submitted website, and retain the timestamp with the classification so downstream consumers can see when the result was updated. Preserve the timestamp as returned; do not assume a timezone or format without checking the response and documentation.
Confidence is a signal to use in your own decision policy, not a substitute for that policy. For example, you might accept a category for CRM enrichment while routing an uncertain result to a human before blocking access or rejecting an ad placement. Record the returned value and the policy version that produced the decision so you can revisit it later.
A broader Klazify response example
The following is the supplied general Klazify response example, not an example of the real-time endpoint’s response to the request above. It illustrates how category names, confidence values, and an IAB mapping can appear alongside other domain intelligence. Do not assume the real-time endpoint returns the company, logo, social, registration, or similar-domain fields shown here.
{
"domain": {
"categories": [
{
"confidence": 0.92,
"name": "/Computers & Electronics/Consumer Electronics",
"IAB-632-596": "Consumer Electronics/Technology & Computing/Consumer Electronics"
},
{
"confidence": 0.89,
"name": "/Internet & Telecom/Mobile & Wireless/Mobile Phones"
}
],
"social_media": null,
"logo_url": "https://klazify.s3.amazonaws.com/2110787991611585019600ed5fb1d1300.04730104.png"
},
"success": true,
"objects": {
"company": {
"url": "https://www.apple.com/",
"name": "Apple",
"city": "Cupertino",
"stateCode": "CA",
"countryCode": "US",
"employeesRange": "100K+",
"revenue": 274515000000,
"raised": null,
"tags": [
"E-commerce",
"Consumer Electronics",
"Mobile",
"B2C"
],
"tech": [
"omniture_adobe_analytics",
"atlassian_confluence",
"successfactors",
"apache_apex",
"talend",
"oracle_peoplesoft",
"salesforce",
"stripe",
"dell_boomi_atomsphere",
"gigya",
"sage_50cloud",
"quickbooks",
"webmethods",
"apache_tomcat",
"alteryx",
"tibco_rendezvous",
"atlassian_jira",
"..."
]
}
},
"domain_registration_data": {
"domain_age_date": "1987-02-19",
"domain_age_days_ago": "13026",
"domain_expiration_date": "2030-02-20",
"domain_expiration_days_left": "123"
},
"similar_domains": [
"bestbuy.com",
"icloud.com",
"microsoft.com",
"macrumors.com",
"google.com",
"samsung.com",
"twitter.com",
"hp.com",
"bhphotovideo.com",
"dell.com"
]
}
In this broader example, domain.categories contains category entries; each shown entry has a name and confidence. The first also includes an IAB mapping. A downstream categorization process could retain the original category and confidence, then look up the category in an internal mapping table rather than hard-coding a business decision into the API client.
The other fields illustrate a different kind of enrichment: social_media is null in this example, while logo_url, company details, registration data, and similar domains are present. Null values need explicit handling, and these extra fields should not be expected from the live categorization request unless the applicable endpoint documentation says they are available.
Build a dependable classification workflow
Map the response to a decision
Keep Klazify’s returned category separate from your organization’s action. An internal mapping might associate a recognized category with an enrichment label, an ad-review queue, or a filtering rule. Preserve the original category alongside the mapped label so a taxonomy change does not erase the evidence behind an earlier decision.
Decide what happens when several categories are returned. An ad-safety workflow might review any relevant category, while a CRM workflow might store all categories for later segmentation. Neither workflow should silently discard a category just because another has a higher confidence value.
Set confidence thresholds through your own evaluation process, based on the cost of a wrong decision. For a high-impact block, a category match can trigger review rather than automatic enforcement. For enrichment, it may be acceptable to store an uncertain label as unconfirmed instead of presenting it as a verified fact.
Cache deliberately
Cache results per normalized domain when the decision is domain-wide. Store the returned categories, confidence values, domain_url, and updated_at with the time your application retrieved the result. A cache hit avoids another live call, but it also means the application is using an earlier result; choose a freshness policy appropriate to the decision.
Do not collapse every URL to a domain if your use case depends on differences between pages. Keep the submitted URL available for audit, and choose cache keys that match the scope your policy evaluates. When the cache entry is stale, request a fresh result and replace it only after validating the new response.
Queue work and handle exceptions
For large lists, place individual classifications on a work queue and control concurrency rather than launching an unrestricted burst of requests. Check the applicable rate limits for your account in the documentation, and use backoff for temporary failures. The request shown here sends one URL; do not assume a bulk request format without confirming it in the documentation.
New, unreachable, or otherwise unclassified domains need an explicit outcome. Mark them as unknown, retain the reason when available, and route them to retry or review according to your application’s risk tolerance. Avoid treating “no category” as either a safe classification or a prohibited one by default.
Monitor request failures, cache hits, unknown results, and decisions sent for review. Failed or unreachable calls are not billed, but they still affect latency and workflow completion, so they deserve operational attention. The Starter plan is $39.99 per month with a 7-day trial; check your account details for the limits that apply to your workload.
FAQ
Does the real-time request need a refresh parameter?
No. Send the URL in the JSON body; every call to this endpoint is live.
Can I use the result to block a website automatically?
You can map returned categories to your own filtering policy, but define how confidence, multiple categories, and unknown results affect the decision. For consequential blocks, a review path helps avoid treating an uncertain classification as a final verdict.
What should I do if a domain has no usable category?
Keep it in an unknown state rather than inventing a label. Retry when appropriate, or send it for review; keep request failures distinct from valid but unusable results.
Can other tools access Klazify alongside my PHP service?
Klazify also provides an MCP resource. Use the integration that fits your workflow, and keep its authorization and policy decisions under your application’s control.
Ready to classify a URL from your application? Register for a free account, obtain your key, and test the live request before connecting the result to your enrichment, audit, or filtering pipeline.
Ready to use Klazify?
Start classifying websites, enriching company data, and exploring web intelligence.
Get Started Free