zero-to-prod / stream-socket-cli
A CLI for a stream socket.
Fund package maintenance!
Github
Requires
- php: >=8.1
- ext-json: *
- symfony/console: ^7.2
- zero-to-prod/data-model: ^81.13
- zero-to-prod/package-helper: ^1.1.3
- zero-to-prod/stream-socket: ^81.0
Requires (Dev)
- phpunit/phpunit: <12.0
README
Contents
- Introduction
- Requirements
- Installation
- Documentation Publishing
- Usage
- Docker Image
- Local Development
- Image Development
- Contributing
Introduction
A CLI for a stream socket.
Requirements
- PHP 8.1 or higher.
Installation
Install Zerotoprod\StreamSocketCli
via Composer:
composer require zero-to-prod/stream-socket-cli
This will add the package to your project's dependencies and create an autoloader entry for it.
Documentation Publishing
You can publish this README to your local documentation directory.
This can be useful for providing documentation for AI agents.
This can be done using the included script:
# Publish to default location (./docs/zero-to-prod/stream-socket-cli) vendor/bin/zero-to-prod-stream-socket-cli # Publish to custom directory vendor/bin/zero-to-prod-stream-socket-cli /path/to/your/docs
Automatic Documentation Publishing
You can automatically publish documentation by adding the following to your composer.json
:
{ "scripts": { "post-install-cmd": [ "zero-to-prod-stream-socket-cli" ], "post-update-cmd": [ "zero-to-prod-stream-socket-cli" ] } }
Usage
Run this command to see the available commands:
vendor/bin/stream-socket-cli list
Available Commands
stream-socket-cli:src
Displays the project's GitHub repository URL.
Usage:
vendor/bin/stream-socket-cli stream-socket-cli:src
Example:
vendor/bin/stream-socket-cli stream-socket-cli:src
Output:
https://github.com/zero-to-prod/stream-socket-cli
stream-socket-cli:remote-socket-name
Returns the remote socket name for a given URL connection.
Usage:
vendor/bin/stream-socket-cli stream-socket-cli:remote-socket-name <url>
Arguments:
url
(required): The URL to connect to
Example:
vendor/bin/stream-socket-cli stream-socket-cli:remote-socket-name ssl://google.com:443
Output:
74.125.224.102:443
stream-socket-cli:local-socket-name
Returns the local socket name for a given URL connection.
Usage:
vendor/bin/stream-socket-cli stream-socket-cli:local-socket-name <url>
Arguments:
url
(required): The URL to connect to
Example:
vendor/bin/stream-socket-cli stream-socket-cli:local-socket-name ssl://google.com:443
Output:
192.168.1.100:52345
stream-socket-cli:send-to
Sends a message to a socket, whether it is connected or not.
Usage:
vendor/bin/stream-socket-cli stream-socket-cli:send-to <url> <data> [--flags] [--address]
Arguments:
url
(required): The URL to connect todata
(required): The data to be sent
Options:
--flags
: The value of flags can be any combination of the following: STREAM_OO--address
: The address specified when the socket stream was created will be used unless an alternate address is specified in address. If specified, it must be in dotted quad (or [ipv6]) format
Example:
vendor/bin/stream-socket-cli stream-socket-cli:send-to tcp://httpbin.org:80 "GET / HTTP/1.1\r\nHost: httpbin.org\r\n\r\n"
Output:
42
stream-socket-cli:supports-lock
Tells whether the stream supports locking. Returns the URL for true, otherwise returns an empty string.
Usage:
vendor/bin/stream-socket-cli stream-socket-cli:supports-lock <url>
Arguments:
url
(required): The URL to connect to
Example:
vendor/bin/stream-socket-cli stream-socket-cli:supports-lock ssl://google.com:443
Output (if supports locking):
ssl://google.com:443
Output (if doesn't support locking):
stream-socket-cli:get-options
Retrieve options for a stream/wrapper/context.
Usage:
vendor/bin/stream-socket-cli stream-socket-cli:get-options <url>
Arguments:
url
(required): The URL to connect to
Example:
vendor/bin/stream-socket-cli stream-socket-cli:get-options ssl://google.com:443
Output:
{ "ssl": { "peer_name": "google.com", "verify_peer": true, "verify_peer_name": true } }
Docker Image
You can also run the cli using the docker image:
docker run --rm davidsmith3/stream-socket-cli
Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page if you want to contribute.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Create a new Pull Request.