Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very long time to show #55

Open
hrace009 opened this issue Apr 14, 2022 · 26 comments
Open

Very long time to show #55

hrace009 opened this issue Apr 14, 2022 · 26 comments

Comments

@hrace009
Copy link

Captcha show with very long time, i don't know why, but this is using localhost with xampp and php 8.1
image

@mishinroman94
Copy link

I have the same problem. Works fine on php 8.0

@hrace009
Copy link
Author

yeah, last time i use php7.4 it working fine, but when i switch to php8.1 the code show very long time

@some0ne2
Copy link

Can confirm this, switched from working PHP7.4 to PHP8.1 (tried laravel8 and laravel9), same effect. as soon as I switch PHP to 8.1 the whole page speed is ruined.

Not usable in production.
@igoshev any idea where things go wrong / can you take a look into?

@hrace009
Copy link
Author

@igoshev please make a fix for this

@hrace009
Copy link
Author

i don't see any respond from @igoshev

@hrace009
Copy link
Author

seems we must make our own fix for this package

@some0ne2
Copy link

@tm1000 any idea maybe since you pushed the commit for laravel9?

@some0ne2
Copy link

unusable for PHP8.1

@tm1000
Copy link
Contributor

tm1000 commented Jun 28, 2022

@some0ne2 if you look at my commit you can see that I only bumped the composer file

Regardless my company has five services that use this on php 8.1 for the last two-three months and we've experienced no issues

@some0ne2
Copy link

@tm1000 Thanks for information, what laravel version and what PHP version exactly are you using?

@tm1000
Copy link
Contributor

tm1000 commented Jun 28, 2022

Laravel 9 and php 8.1.7

@tm1000
Copy link
Contributor

tm1000 commented Jun 28, 2022

My coworker was confused on what I was asking. Yes we are experiencing the slowness too. The issue is all of the math in

$sx = $x + (sin($x * $sxR1 + $sxF1) + sin($y * $sxR2 + $sxF2)) * $sxA;
$sy = $y + (sin($x * $syR1 + $syF1) + sin($y * $syR2 + $syF2)) * $syA;
if ($sx < 0 || $sy < 0 || $sx >= $params['width'] - 1 || $sy >= $params['height'] - 1) {
$r = $rX = $rY = $rXY = $bgColor['r'];
$g = $gX = $gY = $gXY = $bgColor['g'];
$b = $bX = $bY = $bXY = $bgColor['b'];
} else {
$rgb = imagecolorat($img1, $sx, $sy);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$rgb = imagecolorat($img1, $sx + 1, $sy);
$rX = ($rgb >> 16) & 0xFF;
$gX = ($rgb >> 8) & 0xFF;
$bX = $rgb & 0xFF;
$rgb = imagecolorat($img1, $sx, $sy + 1);
$rY = ($rgb >> 16) & 0xFF;
$gY = ($rgb >> 8) & 0xFF;
$bY = $rgb & 0xFF;
$rgb = imagecolorat($img1, $sx + 1, $sy + 1);
$rXY = ($rgb >> 16) & 0xFF;
$gXY = ($rgb >> 8) & 0xFF;
$bXY = $rgb & 0xFF;
}
if (
$r == $rX &&
$r == $rY &&
$r == $rXY &&
$g == $gX &&
$g == $gY &&
$g == $gXY &&
$b == $bX &&
$b == $bY &&
$b == $bXY
) {
if ($r == $bgColor['r'] && $g == $bgColor['g'] && $b == $bgColor['b']) {
$newR = $bgColor['r'];
$newG = $bgColor['g'];
$newB = $bgColor['b'];
} else {
$newR = $textColor['r'];
$newG = $textColor['g'];
$newB = $textColor['b'];
}
} else {
$frsx = $sx - floor($sx);
$frsy = $sy - floor($sy);
$frsx1 = 1 - $frsx;
$frsy1 = 1 - $frsy;
$newR = floor($r * $frsx1 * $frsy1 +
$rX * $frsx * $frsy1 +
$rY * $frsx1 * $frsy +
$rXY * $frsx * $frsy);
$newG = floor($g * $frsx1 * $frsy1 +
$gX * $frsx * $frsy1 +
$gY * $frsx1 * $frsy +
$gXY * $frsx * $frsy);
$newB = floor($b * $frsx1 * $frsy1 +
$bX * $frsx * $frsy1 +
$bY * $frsx1 * $frsy +
$bXY * $frsx * $frsy);
}
imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newR, $newG, $newB));

On individual runs it takes about 0.002 seconds. However once you multiply that by each of the foreachs such as the width (120) and height (80) you get 20 seconds. The smaller the image the less time it would take.

Instead of looking into this further I just switched to: https://github.com/mewebstudio/captcha

Not the ideal solution but it works for now.

@some0ne2
Copy link

@tm1000 Thanks for update, any idea why this might occur only when we switch to PHP8.1?
Yes I know mewebstudio, but for us this is not ideal too, that's why we switched to this captcha lib.

@tm1000
Copy link
Contributor

tm1000 commented Jun 28, 2022

@some0ne2 it's a bug in php not anything with this library. The math functions are slightly slower in php 8.1 and thus causes slowdowns.

@tm1000
Copy link
Contributor

tm1000 commented Jun 28, 2022

The solution here is probably to replace WaveGenerator with code that uses https://github.com/Intervention/image to generate a similar image (this is what mewebstudio does)

The math however is used to create the wavy text

@some0ne2
Copy link

Did they replace the wave generator because of the bug in PHP8.1 too?

@tm1000
Copy link
Contributor

tm1000 commented Jun 28, 2022

@some0ne2 they dont use WaveGenerator. WaveGenerator is exclusive to this library

@some0ne2
Copy link

Someone with free time available? Would provide some cups of coffee (tips) for fixing :).

@hrace009
Copy link
Author

i think we should upgrade to PHP 8.2

@some0ne2
Copy link

@hrace009 Not released, anybody an update on to this?
@tm1000 Thanks for verification, is this bug documented somewhere on PHP bugtracker?

@hrace009
Copy link
Author

@some0ne2 i have seen PHP 8.2 somewhere, but still in dev mode

@mohammadmahdavim
Copy link

hi every body
Still haven't found a solution for this?

@some0ne2
Copy link

some0ne2 commented Dec 3, 2022

Any update onto this?
Someone tried 8.2 release of PHP?

@tm1000
Copy link
Contributor

tm1000 commented Dec 4, 2022

I switched captcha providers

@some0ne2
Copy link

@tm1000 any recommendation?

@tm1000
Copy link
Contributor

tm1000 commented Jun 11, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants