{"id":15683381,"url":"https://github.com/belgattitude/pjbserver-tools","last_synced_at":"2025-07-03T20:33:25.108Z","repository":{"id":52569489,"uuid":"46614422","full_name":"belgattitude/pjbserver-tools","owner":"belgattitude","description":"PHP JavaBridge server tools","archived":false,"fork":false,"pushed_at":"2021-04-25T17:33:24.000Z","size":2259,"stargazers_count":10,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-29T01:37:33.029Z","etag":null,"topics":["cli","php-java-bridge","soluble-japha"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/belgattitude.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-21T12:29:19.000Z","updated_at":"2021-09-29T19:57:37.000Z","dependencies_parsed_at":"2022-09-11T06:02:49.785Z","dependency_job_id":null,"html_url":"https://github.com/belgattitude/pjbserver-tools","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/belgattitude/pjbserver-tools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belgattitude%2Fpjbserver-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belgattitude%2Fpjbserver-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belgattitude%2Fpjbserver-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belgattitude%2Fpjbserver-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/belgattitude","download_url":"https://codeload.github.com/belgattitude/pjbserver-tools/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belgattitude%2Fpjbserver-tools/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263399913,"owners_count":23460783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","php-java-bridge","soluble-japha"],"created_at":"2024-10-03T17:04:52.213Z","updated_at":"2025-07-03T20:33:25.084Z","avatar_url":"https://github.com/belgattitude.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pjbserver-tools\n[![PHP Version](http://img.shields.io/badge/php-5.5+-ff69b4.svg)](https://packagist.org/packages/belgattitude/pjbserver-tools)\n[![PHP Version](https://img.shields.io/badge/php-7.1+-ff69b4.svg)](https://packagist.org/packages/belgattitude/pjbserver-tools)\n[![PHP Version](https://img.shields.io/badge/php-8.0+-ff69b4.svg)](https://packagist.org/packages/belgattitude/pjbserver-tools)\n[![Build Status](https://travis-ci.org/belgattitude/pjbserver-tools.svg?branch=master)](https://travis-ci.org/belgattitude/pjbserver-tools)\n[![codecov](https://codecov.io/gh/belgattitude/pjbserver-tools/branch/master/graph/badge.svg)](https://codecov.io/gh/belgattitude/pjbserver-tools)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/belgattitude/pjbserver-tools/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/belgattitude/pjbserver-tools/?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/belgattitude/pjbserver-tools/v/stable.svg)](https://packagist.org/packages/belgattitude/pjbserver-tools)\n[![Total Downloads](https://poser.pugx.org/belgattitude/pjbserver-tools/downloads.svg)](https://packagist.org/packages/belgattitude/pjbserver-tools)\n[![License](https://poser.pugx.org/belgattitude/pjbserver-tools/license.svg)](https://packagist.org/packages/belgattitude/pjbserver-tools)\n\nThe `pjbserver-tools` package currently provides an easy installable php java bridge standalone server.\nSee the [soluble/japha](https://github.com/belgattitude/soluble-japha) and [php-java-bridge](https://github.com/belgattitude/php-java-bridge)\nprojects to get more info about php/java integration.\n\n\u003e **Note** that the `pjbserver-tools` standalone server utility\n\u003e was made for easy composer installation when developing or testing.\n\u003e\n\u003e **For production, building a customized PHPJavaBridge server is\n\u003e really easy. Check the recommended [php/java/bridge installation notes](http://docs.soluble.io/soluble-japha/install_server/)**\n\n\n## Use cases\n\nThe java bridge standalone server can be used as an alternative to a regular bridge installation\nfor php/java integration while keeping things simple for development, unit testing or small projects.\n\n## Features\n\n- Easy setup of a PHP Java bridge standalone server (*nix).\n- Console commands to control the server (start/stop/restart/status).\n- API library to customize the behaviour.\n- Includes compiled [JavaBridge.jar](./resources/pjb713_standalone/JavaBridge.jar) 7.1.3 file.\n\n## Requirements\n\n- PHP 5.5+, 7.0 or HHVM \u003e= 3.2.\n- Linux/Unix *(Mac OSX 10.1+ reported working)*.\n- Java 1.7+ (see [install instructions](./doc/install_java.md)).\n\n## Installation\n\n\u003e **WARNING** The phpjavabridge server is not supposed to be run on a public facing server\n\u003e and its use should be limited to interactions on the same host/network with the php client.\n\u003e Do not run it as root neither as it exposes the JVM methods through the network that\n\u003e could be remotely exploited. Do not start it as root neither.\n\nDepending on your needs you can use the pjserver-tools in two ways.\n\n1. Option 1: Composer install\n\n   You can easily add the pjbserver-tools to your existing [composer](http://getcomposer.org/) project.\n\n    ```console\n    $ composer require belgattitude/pjbserver-tools\n    ```\n\n    It can also be added to your development dependencies (replace `require` by `require --dev` in the\n    previous command). Very helpful if you intend to test with Travis...\n\n    Test a command line.\n\n    ```console\n    ./vendor/bin/pjbserver-tools pjbserver:status ./vendor/belgattitude/pjbserver-tools/config/pjbserver.config.php.dist -vvv\n    ```\n\n\n2. Option 2: Console, clone the repo.\n\n   First create a path on your filesystem that will hold the server install.\n\n   ```console\n   $ mkdir -p /my/path/pjbserver-tools\n   $ cd /my/path/pjbserver-tools\n   ```\n\n   Clone the repository and use run [composer](http://getcomposer.org) update.\n\n   ```console\n   $ git clone https://github.com/belgattitude/pjbserver-tools.git\n   $ cd pjbserver-tools\n   $ composer update\n   ```\n\n   Test a command line\n\n   ```\n   ./bin/pjbserver-tools pjbserver:status ./config/pjbserver.config.php.dist -vvv\n   ```\n\n\n## Usage\n\n### Command line\n\nCommand line depends on your install method (composer or clone/download).\n\n- With composer the location of the binary is `./vendor/bin/pjbserver-tools` and the default\n  config is located in `./vendor/belgattitude/pjbserver-tools/config/pjbserver.config.php.dist`.\n\n- With the clone method, binary is `./bin/pjbserver-tools` and default config is `./config/pjbserver.config.php.dist`.\n\n*For clarity, the documentation of console commands is based on the clone method. Simply\nreplace your path whenever needed.*\n\nYou can use the commands\n`pjbserver:start`, `pjbserver:stop`, `pjbserver:restart`, `pjbserver:status` followed\nby the `pjbserver.config.php` file to control or query the server status.\n\n\n```console\n$ ./bin/pjbserver-tools pjbserver:start -vvv ./config/pjbserver.config.php.dist\n$ ./bin/pjbserver-tools pjbserver:stop -vvv ./config/pjbserver.config.php.dist\n$ ./bin/pjbserver-tools pjbserver:restart -vvv ./config/pjbserver.config.php.dist\n$ ./bin/pjbserver-tools pjbserver:status -vvv ./config/pjbserver.config.php.dist\n\n$ # for listing the java cli command issued :\n$ ./bin/pjbserver-tools pjbserver:reveal ./config/pjbserver.config.php.dist\n```\n\n\nIf you use the [./config/pjbserver.config.php.dist](./config/pjbserver.config.php.dist) config file, the server will start on port ***8089***.\n\nFeel free to create a local copy of this file and adapt for your usage :\n\n```console\n$ cp ./config/pjbserver.config.php.dist /my/path/pjbserver.config.php\n```\n\n*Note that the -v, -vv, -vvv option in the command line allows to define the verbosity level of the scripts.*\n\n### Controlling via the API\n\nCommand line is good, but API gives a little more control especially good when setting unit tests and CI.\n\nHere's a little example:\n\n```php\n\u003c?php\n\nuse PjbServer\\Tools\\StandaloneServer;\nuse PjbServer\\Tools\\StandaloneServer\\Config;\n\n$tcp_port = 8089;\n\n$config = new Config([\n    // Port on which php java bridge server listen (required)\n    'port' =\u003e $tcp_port,\n\n    /**\n     * Location of log and pid files...\n     * Defaults is to put them in the project 'pjbserver-tools/var/...' directory\n     * which is fine for unit testing, but to prevent loosing those files\n     * set a safe directory (not /tmp as it might be cleared by the OS)\n     */\n    //'log_file'   =\u003e \"/my/path/var/pjbserver-port${tcp_port}.log\",\n    //'pid_file'   =\u003e \"/my/path/var/pjbserver-port${tcp_port}.pid\",\n\n\n    // Optional but often more than useful\n    'classpaths'  =\u003e [\n          '/my/path/*.jar',\n          '/another/path/mylib.jar'\n    ],\n\n    // Standalone server tuning\n    // Number of threads for standalone server is 50, increase if needed\n    //'threads'    =\u003e 50,\n\n    // Java binary\n    // change location if you like, for example\n    // /usr/lib/jvm/java-8-oracle/bin/java\n    'java_bin' =\u003e 'java',\n\n    /**\n     * Location of the JavaBridge.jar,\n     * Default is to use the default (included) one\n     * available in pjbserver-tools/resources/pjb713_standalone/JavaBridge.jar\n     */\n    //'server_jar' =\u003e \"/my/path/pjb713_standalone/JavaBridge.jar\",\n]);\n\n$server = new StandaloneServer($config);\n\ntry {\n    $server-\u003estart();\n} catch(\\Exception $e) {\n    // Exception message\n    echo $e-\u003egetMessage();\n    // Server output logs\n    echo $server-\u003egetOutput();\n    die();\n}\n\necho \"Started: \" . ($server-\u003eisStarted() ? 'yes' : 'no') . PHP_EOL;\necho \"Running: \" . ($server-\u003eisProcessRunning() ? 'yes' : 'no') . PHP_EOL;\necho \"Pid    : \" . $server-\u003egetPid() . PHP_EOL;\n\n// Stopping the server\n\n$server-\u003estop();\n\n```\n\nYou can also inject any PSR-3 compatible logger to the `StandaloneServer`.\n\n```php\n// any PSR-3 compatible logger\n$logger = new \\Psr\\Log\\NullLogger();\n$server = new StandaloneServer($config, $logger);\n\n```\n\n## Configuration\n\nThe dist config file [./config/pjbserver.config.php.dist](https://github.com/belgattitude/pjbserver-tools/blob/master/config/pjbserver.config.php.dist)\ncontains the default parameters used in console mode.\n\n### Parameters\n\n| Key            | Type   | Comment                                          |\n|----------------|--------|--------------------------------------------------|\n| `port`         | int    | TCP port on which standalone server listen       |\n| `classpaths`   | array  | Java additional classpaths                      |\n| `threads`      | int    | Server max number of threads                     |\n| `java_bin`     | string | Java binary executable (with or without path)    |\n| `server_jar`   | string | Path to the JavaBridge.jar file                  |\n| `log_file`     | string | Path to the standalone server log file           |\n| `pid_file`     | string | Path to the standalone pid file                  |\n\nSome considerations:\n\n- When choosing a `port`, ensure it's not available publicly (security).\n- The default config set `log_file` and `pid_file` in the ./var directory, please\n  change the default location to your data directory.\n- Avoid storing `log_file` and `pid_file` in the global temp directory '/tmp' as it might\n  be cleared by the OS at anytime.\n\n### Classpath configuration\n\nWhenever you need to add some java libraries, simply edit the configuration file and look for the\n`classpaths` option and add the required jar files.\n\nAs an example:\n\n```php\n\u003c?php\n\nreturn [\n    'port'       =\u003e 8089,\n    'classpaths' =\u003e [\n        '/my/path/autoload/mysql-connector.jar',\n        '/my/autoload_path/*.jar'\n    ],\n];\n```\n\nDon't forget to restart the standalone server to reflect the changes.\n\n*Using wildcard* `/my/path/*.jar` *is possible but should be used with care. All matching files will be appended to classpath\nby passing arguments in a shell exec. Limits exists...*\n\n## Debugging\n\nSome useful commands to watch, debug and eventually kill java standalone server process\n\n### Getting the status (running/not running)\n\n```console\n$ ./bin/pjbserver-tools pjbserver:status -vvv ./config/pjbserver.config.php.dist\n```\n\n### Reveal the issued command\n\n```console\n$ ./bin/pjbserver-tools pjbserver:reveal -vvv ./config/pjbserver.config.php.dist\n```\n\nFor example, the issued command the default config can be\n\n```console\n$ java -cp \"/xxx/pjbserver-tools/resources/pjb713_standalone/JavaBridge.jar\" -Dphp.java.bridge.daemon=\"false\" -Dphp.java.bridge.threads=50 php.java.bridge.Standalone SERVLET:8089\n```\n\n### Process management\n\nIf for any reason the server cannot be stopped through the console, you can\nlookup the process through the command line.\n\n```console\n$ # Searching by listening port\n$ netstat -nlp | grep :\u003cport\u003e   # might require sudo if server started as root\n\n$ # Searching by name\n$ ps ax | grep JavaBridge.jar\n\n$ # Searching by custom filter\n$ pgrep -f \"(.*)java(.*)JavaBridge.jar(.*)SERVLET:8089\"\n```\n\nYou can kill the process:\n\n```\n$ kill \u003cpid_standalone_server\u003e\n```\n## FAQ\n\n### How to start automatically at boot\n\nCheck for \"supervisord\" on google, you'll find some recipes but the\npreferred method is to deploy on Tomcat, see:\n\n- [pjb-starter-springboot](https://github.com/belgattitude/pjb-starter-springboot/) to build you own production, self-container or deployable servlet or\n- [php-java-bridge](https://github.com/belgattitude/php-java-bridge) project.\n\nFor alternatives to pjbserver-tools standalone.\n\n## Coding standards\n\n* [PSR 4 Autoloader](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md)\n* [PSR 3 Logger interface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md)\n* [PSR 2 Coding Style Guide](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)\n* [PSR 1 Coding Standards](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbelgattitude%2Fpjbserver-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbelgattitude%2Fpjbserver-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbelgattitude%2Fpjbserver-tools/lists"}