PHPackages                             j-angnoe/php-bridge - 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. j-angnoe/php-bridge

ActiveLibrary

j-angnoe/php-bridge
===================

PHP Javascript bridge for prototypes

037PHP

Since Aug 19Pushed 3y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Bridge
==========

[](#php-bridge)

PHP Bridges allows you to interact with a designated php object in javascript without having to deal with routing and marshalling arguments. Spend less time writing boilerplate and fiddling with frameworks, spend more time developing your idea.

An example php object

```
class MyController {
    function performSomeAction($argument1, $argument2) {
        // ...
    }
}
```

Interacting with this object in javascript:

```
var result = await api.performSomeAction(arg1, arg2);
```

By adding:

```
PhpBridge\Bridge::serve(MyController::class)
```

Usage:
------

[](#usage)

PhpBridge is a library and comes with an executable for quickly spinning up local prototypes.

### Using the phpbridge executable

[](#using-the-phpbridge-executable)

PhpBridge will launch a webserver on an available port serving the file (or directory) you specified. It will autoload PhpBridge and provide the `bridge` function so you can write: It will automatically

```
./vendor/bin/phpbridge file.php [--port=1234] [--no-browser]
```

```
// file.php

Execute

    async function execute() {
        var result = await api.fn();
        alert(result);
    }

```

### Using the library:

[](#using-the-library)

```
interrupt();

// Will write window.api = ....
echo $bridge->output('script');
?>

Execute

    async function execute() {
        var result = await api.fn();
        alert(result);
    }

```

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

[](#installation)

Via composer

```
composer require j-angnoe/php-bridge
```

Api
---

[](#api)

PhpBridge\\Bridge::to($targetClass) - Create a bridge instance and provide it with a target class (classname or object)

PhpBridge\\Bridge::interrupt() - Allow PHP Bridge to interrupt the current script's flow to handle the api calls. Call interrupt before starting output.

PhpBridge\\Bridge::output($flags) - Get a copy of the javascript client for your target class.

Features
--------

[](#features)

PhpBridge\\Bridge protects calls with a client/csrf method. This is to prevent any non-browser client to interact with your code via the bridge. In order to benefit from this added layer of security you should make sure a php is started prior to calling interrupt. The phpbridge binary does this for you.

The javascript client requires a browser to have the `fetch` method.

Examples:
---------

[](#examples)

Can be found in ./examples/

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5c43eab887b4a97df5d72331ab607920bf1c4cbcb9883aa1f5b888bee287813?d=identicon)[j-angnoe](/maintainers/j-angnoe)

---

Top Contributors

[![j-angnoe](https://avatars.githubusercontent.com/u/4835885?v=4)](https://github.com/j-angnoe "j-angnoe (31 commits)")

### Embed Badge

![Health badge](/badges/j-angnoe-php-bridge/health.svg)

```
[![Health](https://phpackages.com/badges/j-angnoe-php-bridge/health.svg)](https://phpackages.com/packages/j-angnoe-php-bridge)
```

PHPackages © 2026

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