A simple PHP package to find an available port within a range.
Installation using Composer
$ composer require grantlucas/php-portfinder
The following will return the first available port within the range for the provided host.
require_once(__DIR__ . '/vendor/autoload.php');
use GrantLucas\PortFinder;
$port = PortFinder::range('127.0.0.1', 9901, 9999);