Overview
NativePHP Mobile uses a unique architecture that embeds a PHP server directly inside your mobile application. This allows your Laravel app to run natively on mobile devices without requiring external hosting.Core Components
1. Native Shell App
The mobile app container built with:- iOS: Swift + WebKit (WKWebView)
- Android: Kotlin + WebView
- WebView for rendering your Laravel UI
- Native API access (camera, location, biometrics, etc.)
- PHP runtime environment
- HTTP server for Laravel
2. Embedded PHP Server
NativePHP Mobile bundles a complete PHP runtime inside the app. The server handles requests differently on each platform:Android Request Flow
On Android, requests are processed through a custom bridge located atbootstrap/android/native.php:1-121:
- Normalizes cookies and query parameters
- Captures the HTTP request
- Bootstraps the Laravel kernel
- Handles the request through your application
- Returns the response with performance timing headers
The embedded server includes performance monitoring that logs timing breakdowns for autoload, bootstrap, kernel initialization, and request handling.
3. Native Bridge
The bridge connects PHP to native functionality through thenativephp_call() function:
4. Laravel Integration Layer
TheNativeServiceProvider registers all NativePHP components:
RenderEdgeComponents middleware that sends native UI component data after each request.
Filesystems (NativeServiceProvider.php:163-193):
Registers mobile-specific disks like mobile_public and temp for file operations.
Request Lifecycle
Here’s what happens when a user navigates in your app:- User Interaction: User taps a link or button in the WebView
- HTTP Request: WebView sends request to embedded PHP server (typically
http://localhost:PORT) - Bootstrap: PHP bootstrap script (platform-specific) receives the request
- Laravel Handling: Request flows through Laravel’s routing and middleware
- Response Generation: Your controller/view generates HTML response
- Edge Components:
RenderEdgeComponentsmiddleware sends native UI data - Response Delivery: HTML is returned to WebView
- Native UI Update: Native components (like navigation bars) update if Edge components were used
- Rendering: WebView displays the updated page
The entire request is handled locally on the device - no internet connection required unless your app explicitly makes external API calls.
Platform Detection
Your Laravel app can detect which platform it’s running on:- Serve different layouts for mobile vs web
- Enable platform-specific features
- Adjust UI for iOS vs Android conventions
File Storage
NativePHP Mobile configures special filesystem disks:mobile_public Disk
Mapped to storage/app/public with URL access through /_assets/storage:
temp Disk
Provides access to the device’s temporary directory:
Hot Reload Development
During development, NativePHP Mobile supports hot reload:- File Watcher: Monitors configured paths for changes
- WebSocket Server: Maintains connection to mobile app
- Change Detection: Detects file modifications
- Reload Trigger: Sends reload command via WebSocket
- App Refresh: Mobile app reloads the WebView
config/nativephp.php:
Vite Integration
NativePHP Mobile configures platform-specific Vite hot files (NativeServiceProvider.php:230-244):Performance Considerations
The bootstrap script logs detailed performance metrics:- Keep route files lean
- Use route caching for production
- Minimize service provider boot logic
- Cache configuration and views
- Enable OPcache in production builds
Next Steps
App Lifecycle
Learn about app lifecycle events and how to respond to them
Configuration
Explore all configuration options
Blade Components
Discover native UI components
Building Your App
Learn how to build production apps