Overview
Hot reload enables you to see code changes instantly in your running mobile app without rebuilding or reinstalling. When you save a file, NativePHP detects the change and pushes updates to your app via WebSocket.How It Works
Hot reload uses a multi-component system:Installation
Install Watchman
Watchman is required for file watching: macOS:Verify Installation
Using Hot Reload
With Run Command
Enable hot reload when running your app:--watch (or -W) flag enables file watching automatically.
Standalone Watch Command
Watch an already-running app:Target Specific Device
For iOS, specify a device UDID:Configuration
Watch Paths
Configure which directories to watch inconfig/nativephp.php:
Watch Paths
Files in these directories trigger hot reload:app- PHP application coderesources- Views, CSS, JavaScriptroutes- Route definitionsconfig- Configuration filespublic- Public assets
Exclude Patterns
Patterns to ignore (regex supported):\.git- Git repository filesstorage- Storage directorytests- Test filesnode_modules- Node dependencies\.log- Log files
Server Configuration
Configure the development server inconfig/nativephp.php:
Environment Variables
Customize via.env:
WebSocket Connection
Connection Details
Hot reload uses WebSocket for real-time communication:- Protocol: WebSocket (ws://)
- Default Port: 8081
- Auto-Discovery: Apps automatically discover the dev server via mDNS
Connection Flow
Manual Connection
If auto-discovery fails, you can manually configure the server address.File Watching Details
Watched File Types
By default, these extensions trigger hot reload:php- PHP filesblade.php- Blade templatesjs- JavaScript filescss- Stylesheetsts- TypeScript filesvue- Vue componentsjson- JSON configuration
server.watch_extensions:
Excluding Files
Exclude files from triggering reload:Integration with Vite
Hot reload works alongside Vite for asset compilation:Vite Dev Server
When using--watch, NativePHP automatically starts the Vite dev server:
- Watchman file watcher
- WebSocket server for hot reload
- Vite dev server for asset compilation
Asset Rebuilding
Vite automatically rebuilds assets when you change:- JavaScript/TypeScript files
- CSS files
- Vue/React components
Platform-Specific Behavior
Android
On Android, hot reload:- Reloads the WebView content
- Preserves app state where possible
- Reconnects WebSocket if connection drops
iOS
On iOS, hot reload:- Reloads the WKWebView content
- Preserves navigation state
- Handles background/foreground transitions
Troubleshooting
Watchman Not Found
WebSocket Connection Failed
Solutions:- Ensure computer and device are on the same network
- Check firewall isn’t blocking port 8081
- Verify
NATIVEPHP_WS_PORTmatches on both sides - Try restarting the watch command
Changes Not Detected
Solutions:- Verify file is in a watched directory
- Check file extension is in
watch_extensions - Ensure file isn’t in
exclude_patterns - Restart Watchman:
watchman shutdown-server
Too Many Files Watched
Port Already in Use
- Kill the process using the port
- Change
NATIVEPHP_WS_PORTto a different port - Restart your development environment
Performance Tips
Exclude unnecessary directories
Exclude unnecessary directories
Add large directories that don’t need watching to
exclude_patterns:Limit watch paths
Limit watch paths
Only watch directories you actively change:
Use specific file extensions
Use specific file extensions
Limit watched extensions to those you use:
Restart Watchman periodically
Restart Watchman periodically
If watching becomes slow, restart Watchman:
Development Workflow
Optimal hot reload workflow:Best Practices
Use for UI work
Hot reload excels for rapid UI iteration and visual tweaks.
Rebuild for major changes
Rebuild the app when changing:
- Native code
- Configuration files
- Dependencies
Same network required
Ensure your computer and device are on the same local network.
Test without hot reload
Periodically test without hot reload to catch bundling issues.
Next Steps
Development Workflow
Learn best practices for mobile development
Packaging
Package your app for distribution