Closed francoisjacquet closed 3 months ago
In order to compare code for
version 1.9
$qr_code = new QrCode();
$qr_code
->setText( $_REQUEST['url'] )
->setSize( 280 ) // 300x300 = 150x150 (Student Photo) scale 2x.
->setPadding( 10 )
->setErrorCorrection( 'high' )
->setForegroundColor( ['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0] )
->setBackgroundColor( ['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0] )
->setLabel( ! empty( $_REQUEST['label'] ) ? $_REQUEST['label'] : '' )
->setImageType( QrCode::IMAGE_TYPE_PNG )
;
// now we can directly output the qrcode
header( 'Content-Type: ' . $qr_code->getContentType() );
$qr_code->render();
version 5.0.7 (or 4.4.7 is almost the same)
$qrCode = QrCode::create( $_REQUEST['url'] )
->setEncoding( new Encoding( 'UTF-8' ) )
->setErrorCorrectionLevel( ErrorCorrectionLevel::High )
->setSize( 280 )
->setMargin( 10 )
->setForegroundColor( new Color( 0, 0, 0 ) )
->setBackgroundColor( new Color( 255, 255, 255 ) );
// Create generic label
$label = Label::create( ! empty( $_REQUEST['label'] ) ? $_REQUEST['label'] : '' )
->setTextColor( new Color( 0, 0, 0 ) );
$writer = new PngWriter();
$result = $writer->write( $qrCode, null, $label );
// Directly output the QR code
header( 'Content-Type: ' . $result->getMimeType() );
echo $result->getString();
Hi @francoisjacquet, when I run your last snippet here (exactly as you placed it) the code generates in approximataly 10ms. Of course I have different hardware here, but this difference is so big I think something else is going on, so I'm curious what is causing the performance issue on your side.
I don't know your exact url
and label
, can you provide those values to make sure it is not caused by specific values? Also, please check if you do not have underlying processes like xdebug running. And if it is really hard to find you could try to use a profiler like Blackfire. Such a tool makes finding the underlying cause a lot easier most of the cases.
Hello @endroid
Thank you for your answer.
I have tried without xdebug, and the difference is huge.
There is now no notable difference between v5.0.7 and v1.9 :)
Hello and thank you for this great library :)
I was using until now version 1.9 to get PHP 5.5 compatibility.
But I now get deprecated errors with PHP 8.3...
So today, I have been testing versions 4.4.7 and the latest, 5.0.7.
They both are really slow compared to version 1.9, and a single PNG takes up to 3 seconds to generate, why is that?