PHPackages                             pushkar/php-useful - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. pushkar/php-useful

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pushkar/php-useful
==================

Contains various classes and functions to many common tasks in PHP.

v3.0.1(6y ago)2755[1 issues](https://github.com/pushkar-anand/php-useful/issues)[1 PRs](https://github.com/pushkar-anand/php-useful/pulls)1MITPHPPHP &gt;=7.3

Since Jun 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/pushkar-anand/php-useful)[ Packagist](https://packagist.org/packages/pushkar/php-useful)[ Docs](https://github.com/pushkar-anand/php-useful)[ RSS](/packages/pushkar-php-useful/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (6)Dependencies (1)Versions (19)Used By (1)

php-useful
==========

[](#php-useful)

A library of all commonly used PHP things.

[Functions.php](https://github.com/pushkar-anand/php-useful/blob/master/src/Functions.php): has some most used functions

[EasyHeaders.php](https://github.com/pushkar-anand/php-useful/blob/master/src/EasyHeaders.php): has methods to easily set headers

[Curl.php](https://github.com/pushkar-anand/php-useful/blob/master/src/Curl.php): a wrapper for PHP ext-curl.

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

[](#installation)

Use composer

`composer require pushkar/php-useful`

Or download the source and include mannualy

Usage
-----

[](#usage)

When using composer require the autoload file at the start of the php script

```
 require_once __DIR__ . '/path/to/vendor/autoload.php';
```

Add the namespace

```
 use PhpUseful\Functions;   // for using the Functions class
 use PhpUseful\EasyHeaders; // for using the EasyHeader class
 use PhpUseful\Curl;        // for using the Curl class;
```

All the methods are static except in the Curl class so you can directly use them without creating the class object.

#### Functions class

[](#functions-class)

Example usage

```
 $random_ str = Functions::randomString(int $length);
```

All the class methods are listed below.

```
    static function randomString(int $length): string      // returns a random string of given length
    static function escapeInput(string $input): string     // returns escaped string for the given input string
```

#### EasyHeaders

[](#easyheaders)

For using methods from Easy class

```
 EasyHeaders::not_found();
```

All the class methods are listed below.

```
/**
* Sends a 301 MOVED PERMANENTLY header.
*/
static function moved_permanently()

/**
* Sends a 302 FOUND header.
*/
static function found()

/**
* Sends a 400 BAD REQUEST header.
*/
static function bad_request()

/**
* Sends a 401 UNAUTHORIZED header.
*/
static function unauthorized()

/**
* Sends a 403 FORBIDDEN header.
*/
static function forbidden()

/**
* Sends a 404 NOT FOUND header.
*/
static function not_found()

/**
* Sends a 408 REQUEST TIMEOUT header.
*/
static function request_timeout()

/**
* Sends a 500 INTERNAL SERVER ERROR header.
*/
static function server_error()

/**
* Sends a 501 NOT IMPLEMENTED header.
*/
static function not_implemented()

/**
* Sends a 502 BAD GATEWAY header.
*/
static function bad_gateway()

/**
* Sends a 503 SERVICE UNAVAULABLE header.
*/
static function service_unavailable()

/**
* Sends a 504 GATEWAY TIMEOUT header.
*/
static function gateway_timeout()

/**
* Sends a 422 Unprocessable Entity header.
*/
static function unprocessable_entity()

/**
* Sends a Content-Type: application/json header.
*/
static function json_header()

/**
* Sends a Content-Type: application/pdf header.
*/
static function pdf_header()

/**
* Sends a Content-Type: application/xml header.
*/
static function xml_header()

/**
* Sends a Content-Type: application/force-download header.
*/
static function download_header()

/**
* Sends a Content-Type: text-html header.
*/
static function html_header()

/**
* Sends a Content-Type: text/css header.
*/
static function css_header()

/**
* Sends a Content-Type: text/javascript header.
*/
static function js_header()

/**
* Sends a Content-Type: text/plain header.
*/
static function text_header()
```

#### Curl class

[](#curl-class)

Example usage

```
    require_once __DIR__ . '/path/to/vendor/autoload.php';
    use PhpUseful\Curl;

    $curl = new Curl();
    $curl->setUrl('http://example.com');
    $curl->execute();
```

All methods

```
    //Required. sets the url for the curl request. Throws Exception on invalid url.
    function setUrl(string $url)

    // Set headers for the curl request
    function setHeaders(array $headers)

    // when set to true it return the result of the curl_exec() as a string instead of outputting it directly.
    function setReturn(bool $bool)

    // when set to true POST method is used for the curl request
    function usePost(bool $bool)

    // set data to be sent via POST. For this to work usePost() should be set to true
    function setArrayPostData(array $data)

    // set data to be sent via POST. For this to work usePost() should be set to true
    function setStringPostData(string $data)

    // set the port number which will be used for the request
    function setPort(int $port)

    // set the max number of redirects that this request will follow
    function setMaxRedirects(int $max)

    // set the timeout for this request (in seconds)
    function setTimeout(int $timeout)

    // set the username and password to be used for HTTP authentication
    function setCredentials(string $username, string $password)

    // set any valid CURL option in case a helper method isn't present
    function setOption(int $option, mixed $value)

    // Call this after setting all url, headers, method & data
    function execute()

    // return the headers sent for the curl request.
    function getSentHeader()

    // return the reponse. Will work only when setReturn() is set to true.
    function getResult()
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 89.1% 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 ~30 days

Recently: every ~12 days

Total

18

Last Release

2381d ago

Major Versions

v0.3.1 → v1.0.02018-10-07

v1.0.5 → v2.0.02019-09-06

v2.0.3 → v3.0.02019-11-07

PHP version history (2 changes)v0.1PHP &gt;=7.0

v2.0.0PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/57b9bfe4786ed56407a0a6ca136f2dc28098c59666f254a84b0369c096fbb878?d=identicon)[pushkar](/maintainers/pushkar)

---

Top Contributors

[![pushkar-anand](https://avatars.githubusercontent.com/u/13116715?v=4)](https://github.com/pushkar-anand "pushkar-anand (57 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (2 commits)")[![jackey8616](https://avatars.githubusercontent.com/u/12930377?v=4)](https://github.com/jackey8616 "jackey8616 (2 commits)")[![Ashwin-Kapes](https://avatars.githubusercontent.com/u/510118?v=4)](https://github.com/Ashwin-Kapes "Ashwin-Kapes (1 commits)")[![jacobbrunson](https://avatars.githubusercontent.com/u/910953?v=4)](https://github.com/jacobbrunson "jacobbrunson (1 commits)")[![vladootz](https://avatars.githubusercontent.com/u/119264?v=4)](https://github.com/vladootz "vladootz (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pushkar-php-useful/health.svg)

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

###  Alternatives

[magarrent/laravel-url-shortener

Simpler Url Shortener for Laravel

557.4k](/packages/magarrent-laravel-url-shortener)

PHPackages © 2026

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