PHPackages                             hugsbrugs/php-http - 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. hugsbrugs/php-http

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

hugsbrugs/php-http
==================

PHP HTTP Utilities

v2.0.1(4y ago)06061[2 PRs](https://github.com/hugsbrugs/php-http/pulls)1PHPPHP &gt;=7.4

Since Mar 15Pushed 3y ago1 watchersCompare

[ Source](https://github.com/hugsbrugs/php-http)[ Packagist](https://packagist.org/packages/hugsbrugs/php-http)[ RSS](/packages/hugsbrugs-php-http/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (6)Versions (8)Used By (1)

php-http
========

[](#php-http)

This library provides PHP utilities functions to manage URLs. Read [PHP DOC](https://hugsbrugs.github.io/php-http)

[![Build Status](https://camo.githubusercontent.com/e510cf57f30335ca2003bdc08230aa757f7786b57fe21dfa882b25feb115799f/68747470733a2f2f7472617669732d63692e6f72672f6875677362727567732f7068702d687474702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/hugsbrugs/php-http)[![Coverage Status](https://camo.githubusercontent.com/3481912151dfd7ad567ed8c1dbc59a3dc14f225f72a79df5944ad7aa72d7497d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6875677362727567732f7068702d687474702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/hugsbrugs/php-http?branch=master)

Install
-------

[](#install)

Install package with composer

```
composer require hugsbrugs/php-http

```

In your PHP code, load librairy

```
require_once __DIR__ . '/../vendor/autoload.php';
use Hug\Http\Http as Http;
```

Configuration
-------------

[](#configuration)

In order to use cache mechanism, define following constants

```
define('PDP_PDO_DSN', 'mysql:host=localhost;dbname=database');
define('PDP_PDO_USER', 'username');
define('PDP_PDO_PASS', 'password');
define('PDP_PDO_OPTIONS', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
```

Alternatively define path to the local stored [public suffix list](https://publicsuffix.org/list/public_suffix_list.dat)

```
define('PUBLIC_SUFFIX_LIST', realpath(__DIR__ . '/../../../cache/public_suffix_list.dat'));
```

This method should not be used in production since it's really slow.

Otherwise the default, not accurate, cache/public\_suffix\_list.dat file will be used.

Usage
-----

[](#usage)

Execute shell nslookup command

```
Http::nslookup($url);
```

Check if an url is accessible (means not a 404)

```
Http::is_url_accessible($url);
```

Returns HTTP code for given URL

```
Http::get_http_code($url);
```

Cleans an url from its query parameters

```
Http::url_remove_query($url);
```

Cleans an url from its query parameters and path

```
Http::url_remove_query_and_path($url);
```

Quick and dirty function to save an image from the internet

```
Http::grab_image($url, $save_to);
```

Returns basic HTTP headers for a CURL request

```
Http::get_default_headers($host);
```

Extracts suffix, tld, domain and subdomain from an URL

```
Http::extract_all_from_url($url);
```

Extracts extention from an URL

```
Http::extract_extension_from_url($url);
```

Extracts scheme (ftp, http) from an URL

```
Http::extract_scheme_from_url($url);
```

Extracts a TLD (Top Level Domain) from an URL

```
Http::extract_tld_from_url($url);
```

Extracts a sub domain from an URL

```
Http::extract_subdomain_from_url($url);
```

Extracts a domain name from an URL

```
Http::extract_domain_from_url($url);
```

Separates Headers from Body in CURL response

```
Http::extract_request_headers_body($html_with_headers);
```

Sets a php script desired status code (usefull for API)

```
Http::header_status($statusCode);
```

Gets the address and/or http code that the provided URL redirects to. $return can be : url/code/all

```
Http::get_redirect_url($url, $timeout = 5, $return = 'url');
```

Follows and collects all redirects, in order, for the given URL.

```
Http::get_all_redirects($url);
```

Gets the address and/or http code that the URL ultimately leads to. $return can be : url/code/all

```
Http::get_final_url($url, $return = 'url');
```

Check a TXT record in domain zone file

```
Http::check_txt_record($domain, $txt);
```

Waits and tests every minute if domain zone has correct IP adress and TXT record set

```
Http::wait_for_zone_ok($domain, $ip, $txt_record, $wait_minutes = 15);
```

Tests if domain zone has correct IP adress and TXT record set

```
Http::is_zone_ok($domain, $ip, $txt_record);
```

Get name servers of given domain

```
Http::get_name_servers('maugey.fr');
```

Add escaped fragment to URL

```
Http::add_escaped_fragment($url);
```

To enable CORS, put this line at top of your PHP script

```
Http::cors();
```

Converts an URL to a filename It does not encode URL parameters (only scheme - domain - folders - file)

```
Http::url_2_filename($url);
```

Dependecies
-----------

[](#dependecies)

[https://publicsuffix.org/list/public\_suffix\_list.dat](https://publicsuffix.org/list/public_suffix_list.dat)

Unit Tests
----------

[](#unit-tests)

```
composer exec phpunit
phpunit --configuration phpunit.xml

```

Author
------

[](#author)

Hugo Maugey [Webmaster](https://hugo.maugey.fr/webmaster) | [Consultant SEO](https://hugo.maugey.fr/consultant-seo) | [Fullstack developer](https://hugo.maugey.fr/developpeur-web)

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity68

Established project with proven stability

 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

Every ~460 days

Total

5

Last Release

1553d ago

Major Versions

v1.2 → v2.02022-03-30

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

httpphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hugsbrugs-php-http/health.svg)

```
[![Health](https://phpackages.com/badges/hugsbrugs-php-http/health.svg)](https://phpackages.com/packages/hugsbrugs-php-http)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k532.1M19.4k](/packages/laravel-framework)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M524](/packages/shopware-core)[oro/platform

Business Application Platform (BAP)

642140.7k104](/packages/oro-platform)[simplesamlphp/simplesamlphp-module-oidc

A SimpleSAMLphp module adding support for the OpenID Connect protocol

5017.7k1](/packages/simplesamlphp-simplesamlphp-module-oidc)

PHPackages © 2026

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