Skip to content

I developed this solution to enable image generation through a web interface by leveraging the ComfyUI backend.

Notifications You must be signed in to change notification settings

MMTWeb/comfyui-php

Repository files navigation

🚀 Laravel-ComfyUI Bridge

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.


📦 Requirements

  • 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)

🛠️ Installation

1. Clone the Repository

git clone git@github.com:your-username/comfyui-php.git
cd comfyui-php

2. Install Composer Dependencies

composer install

3. Install NPM Dependencies

npm install

4. Environment Configuration

cp .env.example .env

Edit 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

5. Generate App Key

php artisan key:generate

6. Run Laravel Migrations (if needed)

php artisan migrate

7. Start the Laravel Development Server

php artisan serve

or set up your web server to point to /public and visit: http://localhost:chosen port


🪟 Python WebSocket Setup on Windows (ComfyUI Portable)

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.

1. Install Required Packages

.\python.exe -m pip install websocket-client flask

(Run from ComfyUI/python_embeded directory)

2. Move the WebSocket Folder

Place the websocket directory next to the main ComfyUI folder, like this:

D:\ComfyUI\websocket

3. Start the WebSocket Server

cd D:\ComfyUI
.\python_embeded\python.exe websocket\websocket.py

This starts the server Laravel will communicate with.


💡 Why Use a Python WebSocket Instead of Direct PHP API Calls?

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!

📂 Notes

  • vendor/ and node_modules/ directories are excluded. Use composer install and npm install after cloning.

🤝 Contributing

Feel free to open issues or submit pull requests. Any help is appreciated!


📝 License

This project is open-source and freely available for use and modification.

About

I developed this solution to enable image generation through a web interface by leveraging the ComfyUI backend.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published