A custom multi-client, socket-based web server written entirely in PHP.
Supports static file serving, custom routes, file uploads, and downloads.
- Socket-based server using PHP's
socket_*functions - Multi-client support via non-blocking sockets
- Custom routing for GET & POST endpoints
- Static file serving with extension-based MIME detection
- File uploads with validation (max 5 MB, safe filenames, timestamped)
- File downloads with secure path checks
- Request logging with timestamps, IP, status codes
- Security checks for directory traversal and forbidden extensions
root/
│
├── server.php # Main server script
├── public/ # Public static files
│
├── index.html
├──styles.css
├── views/ # PHP templates for dynamic pages
│
├── home.php
├── about.php
├── submit.php
├── uploads/ # Uploaded files (auto-created)
└── logs/ # Server logs (auto-created)
│
└── server.log
- PHP 7.4+ with
socketsextension enabled - CLI access to run the server
- If not present, enable it in php.ini. Check if sockets are enabled:
php -m | grep sockets
php server.php
By default it starts at:
http://127.0.0.1:8080
| Method | Path | Description |
|---|---|---|
| GET | / |
Home page |
| GET | /about |
About page |
| POST | /submit |
Simple form submission |
| POST | /upload |
File upload endpoint |
| GET | /uploads |
List of uploaded files |
| GET | /uploads/{filename} |
Download a file |
- Max file size: 5 MB
- Auto-renames with timestamp to avoid overwrites
- Cleans filenames from special characters
- Only serves allowed file extensions (html, css, js, png, jpg, jpeg, gif, txt)
- Prevents directory traversal attacks
- Upload/download paths restricted to project folders
- Every request is logged to logs/server.log:
[YYYY-MM-DD HH:MM:SS] <client_ip> "<METHOD> <PATH>" <STATUS_CODE>
- This is not production-grade — it’s a learning project.
- Designed to demonstrate socket programming and web server fundamentals in PHP.
- For production, use Apache/Nginx with PHP-FPM.
- PHP Manual – Sockets
- RFC 2616 – HTTP/1.1 Specification
- MIME Types List
- OWASP File Upload Security Guidelines
- PHP File Upload Docs
- Non-blocking Sockets in PHP
👨💻 Developed by - @Arijit2175