This Laravel application connects to ComfyUI through a Python-based WebSocket bridge. It allows you to trigger image generation from Laravel using the ComfyUI backend.
- PHP 8.1+
- Laravel 10.x
- Node.js & NPM
- Composer
- Python 3.x (used through ComfyUI’s embedded version on Windows)
- ComfyUI (Portable version recommended)
git clone git@github.com:your-username/comfyui-php.git
cd comfyui-phpcomposer installnpm installcp .env.example .envEdit the .env file and set the following:
ComfyUIWebSocket=your_websocket_host:your_port- Comment out:
#APP_MAINTENANCE_STORE=database - Set:
APP_MAINTENANCE_DRIVER=file - Set:
DB_CONNECTION=null
php artisan key:generatephp artisan migratephp artisan serveor set up your web server to point to /public and visit: http://localhost:chosen port
If you're using the ComfyUI portable version on Windows, it includes an embedded Python interpreter. You can use it to run the WebSocket bridge without installing Python system-wide.
.\python.exe -m pip install websocket-client flask(Run from ComfyUI/python_embeded directory)
Place the websocket directory next to the main ComfyUI folder, like this:
D:\ComfyUI\websocketcd D:\ComfyUI
.\python_embeded\python.exe websocket\websocket.pyThis starts the server Laravel will communicate with.
Connecting directly from Laravel to ComfyUI's REST API isn't ideal because PHP cannot easily detect when ComfyUI has finished generating an image.
Polling the /history endpoint with timeouts is inefficient and unreliable. PHP's synchronous nature makes it a poor fit for such real-time workflows.
The WebSocket bridge solves this by listening for completion events from ComfyUI and sending the result back to Laravel asynchronously.
If you know a better or more efficient way to handle this, contributions are welcome!
vendor/andnode_modules/directories are excluded. Usecomposer installandnpm installafter cloning.
Feel free to open issues or submit pull requests. Any help is appreciated!
This project is open-source and freely available for use and modification.