PHPackages                             dipeshchangawala/php-url-checker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. dipeshchangawala/php-url-checker

ActiveLibrary[HTTP &amp; Networking](/categories/http)

dipeshchangawala/php-url-checker
================================

A package to check the status code of a URL and detect redirections.

v1.0.0(1y ago)1147MITPHPPHP &gt;=7.4

Since Jan 12Pushed 1y ago1 watchersCompare

[ Source](https://github.com/dipeshchangawala/php-url-checker)[ Packagist](https://packagist.org/packages/dipeshchangawala/php-url-checker)[ RSS](/packages/dipeshchangawala-php-url-checker/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

PHP URL Status Checker
======================

[](#php-url-status-checker)

**PHP URL Status Checker** is a lightweight and flexible PHP package designed to help developers easily verify the status of URLs, extract canonical URLs, validate URLs, and perform other useful URL-related operations.

Features
--------

[](#features)

- Check the HTTP status code of a given URL.
- Validate if a URL is well-formed and accessible.
- Extract the canonical URL from a webpage.
- Detect redirections and retrieve the `Location` header.
- Handle connection errors and timeouts gracefully.
- Extendable with more URL utilities for developers.

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- Guzzle HTTP Client

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require dipeshchangawala/php-url-checker
```

Usage
-----

[](#usage)

### Initialize the Package

[](#initialize-the-package)

```
use Dipeshc\PhpUrlChecker\UrlChecker;

// Initialize the checker with optional Guzzle client settings
$checker = new UrlChecker([
    'timeout' => 15 // Set timeout to 15 seconds (optional)
]);
```

### Check URL Status

[](#check-url-status)

```
$url = 'https://example.com';
$result = $checker->checkStatus($url);

print_r($result);
```

#### Example Output

[](#example-output)

```
Array
(
    [url] => https://example.com
    [status] => 200
    [location] =>
)
```

> If the URL redirects, the location field will contain the redirect URL.

### Validate a URL

[](#validate-a-url)

```
$url = 'https://example.com';
$isValid = $checker->isValidUrl($url);

if ($isValid) {
    echo "$url is a valid URL.";
} else {
    echo "$url is not valid.";
}
```

### Get the Canonical URL

[](#get-the-canonical-url)

```
$url = 'https://example.com';
$canonicalUrl = $checker->getCanonicalUrl($url);

if ($canonicalUrl) {
    echo "The canonical URL for $url is: $canonicalUrl";
} else {
    echo "No canonical URL found for $url";
}
```

#### Example Output

[](#example-output-1)

```
The canonical URL for https://example.com is: https://www.example.com

```

### Detect Redirects

[](#detect-redirects)

```
$url = 'http://example.com';
$redirectLocation = $checker->getRedirectLocation($url);

if ($redirectLocation) {
    echo "The URL redirects to: $redirectLocation";
} else {
    echo "No redirection detected for $url";
}
```

#### Example Output

[](#example-output-2)

```
The URL redirects to: https://example.com

```

### Retrieve all HTTP headers from the given URL

[](#retrieve-all-http-headers-from-the-given-url)

```
$url = 'https://example.com';
$headers = $checker->getHttpHeaders($url);

print_r($headers);
```

#### Example Output

[](#example-output-3)

```
Array
(
    [Content-Type] => text/html; charset=UTF-8
    [Server] => Apache
    [Connection] => keep-alive
)
```

### Check if a URL is reachable and returns a 2xx or 3xx HTTP status code

[](#check-if-a-url-is-reachable-and-returns-a-2xx-or-3xx-http-status-code)

```
$url = 'https://example.com';
$isReachable = $checker->isUrlReachable($url);

if ($isReachable) {
    echo "$url is reachable.";
} else {
    echo "$url is not reachable.";
}
```

#### Example Output

[](#example-output-4)

```
https://example.com is reachable.

```

### Retrieve the entire chain of redirects for a given URL

[](#retrieve-the-entire-chain-of-redirects-for-a-given-url)

```
$url = 'http://example.com';
$redirectChain = $checker->getRedirectChain($url);

if (!empty($redirectChain)) {
    echo "Redirect chain for $url:\n";
    foreach ($redirectChain as $step) {
        echo "URL: {$step['url']}, Status: {$step['status']}\n";
    }
} else {
    echo "$url does not have a redirect chain.";
}
```

#### Example Output

[](#example-output-5)

```
Redirect chain for http://example.com:
URL: http://example.com, Status: 301
URL: https://example.com, Status: 200

```

### Check whether the given URL uses a secure `https` connection

[](#check-whether-the-given-url-uses-a-secure-https-connection)

```
$url = 'https://example.com';
$isSecure = $checker->isSecureUrl($url);

if ($isSecure) {
    echo "$url is a secure URL.";
} else {
    echo "$url is not secure.";
}
```

#### Example Output

[](#example-output-6)

```
https://example.com is a secure URL.

```

### Get the page title for a given URL

[](#get-the-page-title-for-a-given-url)

```
$url = 'https://example.com';
$title = $checker->getPageTitle($url);

echo $title;
```

### Fetch the Content-Type of a URL (e.g., text/html, application/json)

[](#fetch-the-content-type-of-a-url-eg-texthtml-applicationjson)

```
$url = 'https://jsonplaceholder.typicode.com/todos/1';
$type = $checker->getContentType($url);

echo $type;
```

#### Example Output

[](#example-output-7)

```
application/json; charset=utf-8

```

### Validating the syntax of a URL using PHP’s filter\_var

[](#validating-the-syntax-of-a-url-using-phps-filter_var)

```
$url = 'https://example.com';
$isValid = $checker->validateUrlFormat($url);
```

### Check the response time of a given URL (in second).

[](#check-the-response-time-of-a-given-url-in-second)

```
$url = 'https://example.com';
$time = $checker->checkResponseTime($url);

echo $time; // in second(with floating point)
```

### Check for broken links on a given webpage by scanning all href attributes.

[](#check-for-broken-links-on-a-given-webpage-by-scanning-all-href-attributes)

```
$url = 'https://example.com';
$links = $checker->detectBrokenLinks($url);

print_r($links);
```

```
Array
(
    [0] => tel:1000077777
    [1] => https://example.com/tel:988
    [2] => https://example.com/pdfs/forever_decision.pdf
)

```

### Check the status of multiple URLs in a single call

[](#check-the-status-of-multiple-urls-in-a-single-call)

```
$urls = [
    'https://example.com',
    'https://example.com/call2',
    'https://example.com/call3',
];

$links = $checker->checkMultipleUrls($url);

print_r($links);
```

```
Array
(
    [0] => Array
        (
            [url] => "https://example.com"
            [status] => 200
            [location] =>
        )

    [1] => Array
        (
            [url] => "https://example.com/call2"
            [status] => 404
            [location] =>
        )

    [2] => Array
        (
            [url] => "https://example.com/call3"
            [status] => 404
            [location] =>
        )
)

```

Methods Overview
----------------

[](#methods-overview)

MethodDescription`checkStatus($url)`Returns the status code and `Location` header if applicable`isValidUrl($url)`Validates if the given URL is well-formed and accessible`getCanonicalUrl($url)`Extracts the canonical URL from the webpage, if available`getRedirectLocation($url)`Retrieves the Location header for redirects`getRedirectChain($url)`Retrieves the full redirect chain for a given URL`isSecureUrl($url)`Check if a given URL is secure`getResponseHeaders($url)`Get the response headers for a given URL`getPageTitle($url)`Get the page title for a given URL`isReachable($url, $timeout)`Check if a given URL is reachable within a specified timeout period`getContentType($url)`Fetch the Content-Type of a URL`checkMultipleUrls(array $urls)`Check the status of multiple URLs in a single call`validateUrlFormat($url)`A lightweight function to validate the syntax of a URL using PHP’s filter\_var`checkResponseTime($url)`Check the response time of a given URL`detectBrokenLinks($url)`Check for broken links on a given webpage by scanning all href attributesLicense
-------

[](#license)

This package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

This `README.md` gives clear instructions to developers on how to use your package while showcasing its key features. Let me know if you'd like to include additional sections!

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance42

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

483d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a29709e5f307ff73f893838512c6ce8a7e157f7a10d7d1d744b5efc698c27a41?d=identicon)[dipeshchangawala](/maintainers/dipeshchangawala)

---

Top Contributors

[![dipeshchangawala](https://avatars.githubusercontent.com/u/185687905?v=4)](https://github.com/dipeshchangawala "dipeshchangawala (4 commits)")

### Embed Badge

![Health badge](/badges/dipeshchangawala-php-url-checker/health.svg)

```
[![Health](https://phpackages.com/badges/dipeshchangawala-php-url-checker/health.svg)](https://phpackages.com/packages/dipeshchangawala-php-url-checker)
```

###  Alternatives

[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[akamai-open/edgegrid-client

Implements the Akamai {OPEN} EdgeGrid Authentication specified by https://developer.akamai.com/introduction/Client\_Auth.html

482.5M6](/packages/akamai-open-edgegrid-client)[muhammadhuzaifa/telescope-guzzle-watcher

Telescope Guzzle Watcher provide a custom watcher for intercepting http requests made via guzzlehttp/guzzle php library. The package uses the on\_stats request option for extracting the request/response data. The watcher intercept and log the request into the Laravel Telescope HTTP Client Watcher.

98239.8k1](/packages/muhammadhuzaifa-telescope-guzzle-watcher)[onesignal/onesignal-php-api

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

34170.2k2](/packages/onesignal-onesignal-php-api)[ory/hydra-client-php

Documentation for all of Ory Hydra's APIs.

1710.8k](/packages/ory-hydra-client-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
