This sample demonstrates how to decode barcodes and QR codes on the server side using the PHP Laravel framework.
php-barcode-reader.mp4
Instead of compiling a PHP extension (which is tied to a specific PHP version), this project uses a standalone Dynamsoft Barcode Reader Service written in Python. PHP communicates with the service via HTTP and receives JSON results. This approach works across PHP versions without recompiling anything.
PHP 8.x / 7.x <--HTTP/JSON--> Barcode Service (Python + Dynamsoft DBR) <--SDK--> Dynamsoft DBR/DCV
Check the version numbers in the terminal:
python --version
php -v
PHP 7.4.30 (cli) (built: Jun 7 2022 16:24:55) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
php artisan --version
Laravel Framework 8.83.23The demo accepts images up to 20 MB by default. Make sure your PHP installation allows uploads of that size. For the PHP binary at D:\php, edit D:\php\php.ini:
upload_max_filesize = 20M
post_max_size = 20M
memory_limit = 256M
max_execution_time = 60After saving the file, restart the Laravel development server.
-
Install PHP dependencies:
composer install
-
Install Python service dependencies:
cd service pip install -r requirements.txt
-
Apply for a 30-day FREE trial license, and substitute the license key in
service/app.py.LICENSE_KEY = "LICENSE-KEY"
-
Start the barcode service:
cd service python app.pyThe service runs on
http://127.0.0.1:8080by default. You can change the port with theBARCODE_SERVICE_PORTenvironment variable or bind to all interfaces with--host-all. -
Run the web application:
php artisan serve
-
Visit
http://127.0.0.1:8000/barcode_qr_readerin a web browser.The web UI supports:
- Drag and drop images onto the drop zone
- Clicking the drop zone to select a file
- AJAX upload (the page does not reload)
- Auto-fitted image preview
- Canvas overlay showing decoded barcode locations
- A results panel listing barcode format, text, raw bytes, and localization
A command-line test script is provided at test_service.php. Make sure the Python service is running, then:
php test_service.php <path/to/image>How to Decode Barcodes and QR Codes in PHP Laravel with Dynamsoft Barcode SDK