{"id":25277487,"url":"https://github.com/kanti/ssh-tunnel","last_synced_at":"2025-09-11T00:42:38.086Z","repository":{"id":277161362,"uuid":"931537739","full_name":"Kanti/ssh-tunnel","owner":"Kanti","description":"SSH Port forward via PHP Code","archived":false,"fork":false,"pushed_at":"2025-02-12T12:58:26.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-08T06:48:02.803Z","etag":null,"topics":["php","php-library","ssh-forwarding","ssh-tunnel"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kanti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-12T12:55:56.000Z","updated_at":"2025-02-12T12:57:45.000Z","dependencies_parsed_at":"2025-02-12T13:54:25.061Z","dependency_job_id":"edee0458-ce0f-4908-9de0-55d35a184520","html_url":"https://github.com/Kanti/ssh-tunnel","commit_stats":null,"previous_names":["kanti/ssh-tunnel"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Kanti/ssh-tunnel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanti%2Fssh-tunnel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanti%2Fssh-tunnel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanti%2Fssh-tunnel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanti%2Fssh-tunnel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kanti","download_url":"https://codeload.github.com/Kanti/ssh-tunnel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanti%2Fssh-tunnel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274556162,"owners_count":25307506,"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","status":"online","status_checked_at":"2025-09-10T02:00:12.551Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["php","php-library","ssh-forwarding","ssh-tunnel"],"created_at":"2025-02-12T16:55:28.118Z","updated_at":"2025-09-11T00:42:38.044Z","avatar_url":"https://github.com/Kanti.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kanti/ssh-tunnel\n\nThis is a simple SSH tunneling library for PHP.  \nIt allows you to create SSH tunnels to remote servers and use them to forward ports on your local machine to the remote server.\n\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require kanti/ssh-tunnel\n```\n\n## Usage\n\n### tcp:\n````php\n$tunnel = new \\Kanti\\SshTunnel\\SshTunnel(\n    sshHost: \"testServer\", // uses the default ssh config ~/.ssh/config\n    remote: \\Kanti\\SshTunnel\\Remote::tcp(3306, '127.0.0.1'),\n    localPort: null, // if empty will auto select a local port for you (recommended)\n);\n$localPort = $tunnel-\u003estart();\n$connection = new \\PDO('mysql:host=127.0.0.1;port=' . $localPort, 'user', 'password');\n````\n\n### linux socket as tcp port:\n````php\n$tunnel = new \\Kanti\\SshTunnel\\SshTunnel(\n    sshHost: \"testServer\", // uses the default ssh config ~/.ssh/config\n    remote: \\Kanti\\SshTunnel\\Remote::socket('/var/run/mysqld/mysqld.sock'), // can also expose the mysql socket as tcp port.\n    localPort: null,\n);\n$localPort = $tunnel-\u003estart();\n$connection = new \\PDO('mysql:host=127.0.0.1;port=' . $localPort, 'user', 'password');\n````\n\n### advanced usages:\n````php\nuse \\Kanti\\SshTunnel\\SshTunnel;\n\n// tunnel to connect to a remote MySQL server\n$tunnel = new SshTunnel(\n    // set custom ssh settings:\n    sshUser: 'user',\n    sshHost: \"1.1.1.1\",\n    sshPort: 221,\n    remote: \\Kanti\\SshTunnel\\Remote::tcp(3306, '192.168.0.2'),\n    localPort: null,\n);\n$localPort = $tunnel-\u003estart();\n\n// connect to mysql\n$connection = new \\PDO('mysql:host=127.0.0.1;port=' . $localPort, 'user', 'password');\n\n// do something with the connection\n\n$tunnel-\u003estop(); // stops the tunnel\n// OR \nunset($tunnel); // also stops the tunnel (can be disabled in the constructor disconnectAfterTunnelDestroyed: false)\n// OR\n// you can stop the PHP Script, that will also stop the tunnel (via inactivity timeout)\n````\n\n## How does it work?\n\nThe library uses the `ssh` command line tool to create the tunnel.  \nIt uses the control_socket feature of ssh to keep the connection open and reuse it for multiple tunnels (if needed).  \nThe tunnel is created in the background.   \nBy default it will not output anything to the console and will exit after 5s (option: `autoDisconnectTimeout: '10s'`) of inactivity.  \nIf you want to see the output of the tunnel you can set the `debugMasterOutput: true` in the constructor.  \n\n## Linting\n\n``` bash\ncomposer install\ngrumphp run\n```\n\n## Author\n\n````php\nmade with ❤️ by Kanti (Matthias Vogel)\n````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanti%2Fssh-tunnel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanti%2Fssh-tunnel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanti%2Fssh-tunnel/lists"}