Author |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1248 Location: Amsterdam, NL, EU
|
|
Back to top |
|
jimski
Joined: 18 Jan 2014 Posts: 196 Location: USSA
|
Posted: Mon 02 Apr '18 5:20 Post subject: |
|
|
Thanks Jan-E for great PHP releases.
Here are some surprising results from testing PHP xxHash extensions against sha256 on Windows
Input $string: pseudo-random 52 characters long.
Loop: 10,000,000 hashes.
Windows 7 virtual machine 4 cores @ 3Ghz
30.5 sec. hash('sha256', $string)
27.6 sec. xxHash64Unsigned($string)
18.9 sec. xxHash64($string)
Looks like on short strings xxHash64Unsigned is not much faster than sha256 and sha256 produces much better quality hashes.
In contrast regular xxHash is almost 50% fatser than sha256.
Last edited by jimski on Mon 02 Apr '18 22:02; edited 1 time in total |
|
Back to top |
|
jimski
Joined: 18 Jan 2014 Posts: 196 Location: USSA
|
|
Back to top |
|
jimski
Joined: 18 Jan 2014 Posts: 196 Location: USSA
|
Posted: Tue 17 Apr '18 8:11 Post subject: |
|
|
Jan-E is there a reason why PHP evaluates case switch statement in such a weird way.
The following case switch statement prints 'Million' if $value is 0. But evaluates the expression just fine if value is greater than 0.
The same statement works fine if switch (true){..}.
Was there a good reason to implement "case switch" in such a weird counter-intuitive way?
$value = 0;
switch ($value) {
case $value >= 1000000:
print 'Million';
break;
case $value >= 1000 :
print 'Thousand';
break;
default:
print 'Ten';
break;
} |
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1248 Location: Amsterdam, NL, EU
|
Posted: Tue 17 Apr '18 9:54 Post subject: |
|
|
You are mixing the 'if' syntax with the 'case' syntax. Comparisons in a case statement aren't documented. Read http://php.net/manual/en/control-structures.switch.php
Code: | case $value >= 1000000:
print 'Million';
break; |
is probably interpreted as
Code: | if ($value == $value >= 1000000) { print 'Million'; } |
which is quite a weird statement. My guess is that PHP calculates '$value >= 1000000' first and then does the loose comparison, so you should read it as
Code: | if ($value == ($value >= 1000000)) { print 'Million'; } |
If $value = 0, the left side of the ==-comparison is 0 and the right side is FALSE, because ($value >= 1000000) evaluates to FALSE. So the 1st case statement boils down to
Code: | if (0 == FALSE) { print 'Million'; } |
In a loose comparison (==) this will return TRUE:
http://php.net/manual/en/types.comparisons.php#types.comparisions-loose.
Just try this:
Code: | $value = 0;
if ($value == ($value >= 1000000)) { print 'Million'; }
elseif ($value == ($value >= 1000)) { print 'Thousand'; }
else { print 'Ten'; }
|
You will see it prints Million. |
|
Back to top |
|
jimski
Joined: 18 Jan 2014 Posts: 196 Location: USSA
|
Posted: Tue 17 Apr '18 10:51 Post subject: |
|
|
Jan-E wrote: | You are mixing the 'if' syntax with the 'case' syntax. |
Well, the manual suggest that Case Switch and IF are similar without giving any additional warnings. Also it suggests using expressions.
http://php.net/manual/en/control-structures.switch.php
Manual wrote: | The switch statement is similar to a series of IF statements on the same expression... |
What sane programmer, after reading the manual about Case Switch, would come to conclusion that it means: if ($value == $value >= 1000000).
But apart from being weird is there any good reason that you know of for implementing it this way rather than simply making it work as a series of "IF" statements (as the manual suggests). |
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1248 Location: Amsterdam, NL, EU
|
Posted: Tue 17 Apr '18 11:31 Post subject: |
|
|
The manual says they are similar, not equal. The syntax of the switch/case statements differ from 'if' in that switch/case does a loose comparison between the argument of the switch statement and the argument of the case statement. If you are using $value in both switch and case, you are looking for trouble.
jimski wrote: | But apart from being weird is there any good reason that you know of for implementing it this way rather than simply making it work as a series of "IF" statements (as the manual suggests). |
Some programmmers find the switch/case syntax easier to read, but I never use it for two reasons:
1. Both arguments of the comparisons might be far away from each other. The first in the switch statement, the second in every case statement.
2. The comparison is loose (==) and in many cases strict (===) is better. |
|
Back to top |
|
jimski
Joined: 18 Jan 2014 Posts: 196 Location: USSA
|
Posted: Wed 18 Apr '18 2:25 Post subject: |
|
|
Jan-E wrote: |
Some programmmers find the switch/case syntax easier to read, but I never use it for two reasons:
1. Both arguments of the comparisons might be far away from each other. The first in the switch statement, the second in every case statement.
2. The comparison is loose (==) and in many cases strict (===) is better. |
I use case-switch from time to time but I agree with you that any gains from readability or potential speed improvement are inconsequential.
I just run into this problem on one of my clients projects which used comparison expressions as case arguments. At first glance everything works fine until you plug in a value that evaluates to false. I guess sometimes looking under the PHP hood may be a good idea. |
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1248 Location: Amsterdam, NL, EU
|
|
Back to top |
|
laurin1
Joined: 26 Oct 2014 Posts: 74 Location: Flower Mound, TX
|
Posted: Mon 16 Jul '18 22:57 Post subject: LDAP Extension Not Loading |
|
|
I a testing 7.2.27, NTS x86 and the LDAP extension will not load. |
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1248 Location: Amsterdam, NL, EU
|
Posted: Mon 16 Jul '18 23:11 Post subject: |
|
|
The LDAP extension rewuires libsasl.dll, ssleay32.dll and libeay32.dll. See the snapshot.txt. Did you put them in the php-directory?
Otherwise, use the official build which uses OpenSSL 1.1.0:
https://windows.php.net/downloads/releases/php-7.2.7-nts-Win32-VC15-x64.zip
Maybe you should also load the extra sasl dll's. see the sasl2 folder in the zip fron php.net. |
|
Back to top |
|
laurin1
Joined: 26 Oct 2014 Posts: 74 Location: Flower Mound, TX
|
Posted: Tue 17 Jul '18 1:59 Post subject: |
|
|
Quote: |
The LDAP extension rewuires libsasl.dll, ssleay32.dll and libeay32.dll. See the snapshot.txt. Did you put them in the php-directory?
|
Yes.
Quote: |
Maybe you should also load the extra sasl dll's. see the sasl2 folder in the zip fron php.net.
|
I've not had to do that before. Why would I need to do that?
[/quote] |
|
Back to top |
|
laurin1
Joined: 26 Oct 2014 Posts: 74 Location: Flower Mound, TX
|
Posted: Tue 17 Jul '18 23:30 Post subject: |
|
|
LDAP loads fine with official build of 7.2.27 from php.net. |
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1248 Location: Amsterdam, NL, EU
|
Posted: Wed 18 Jul '18 1:55 Post subject: |
|
|
laurin1 wrote: | I've not had to do that before. Why would I need to do that?
|
Probably your previous tests were with PHP 7.0 and PHP 7.1. PHP 7.2 uses in the official build another OpenSSL version than my builds. That does not matter for extensions that don't use OpenSSL, but for the ones that do use OpenSSL you'd better go for the builds from windows.php.net or pecl.php.net |
|
Back to top |
|
laurin1
Joined: 26 Oct 2014 Posts: 74 Location: Flower Mound, TX
|
Posted: Wed 18 Jul '18 19:49 Post subject: |
|
|
I don't understand what you mean, but it's working.
Now, to a different issue:
Warning: Version warning: Imagick was compiled against ImageMagick version 1689 but version 1683 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0
What version of ImageMagick is the php_imagick.dll compiled againsT?
We are currently using:
ImageMagick-6.9.3-7-vc14-x86 |
|
Back to top |
|
laurin1
Joined: 26 Oct 2014 Posts: 74 Location: Flower Mound, TX
|
Posted: Wed 18 Jul '18 20:02 Post subject: |
|
|
Never mind, I found that info in your phpinfo.htm file and thanks. |
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1248 Location: Amsterdam, NL, EU
|
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1248 Location: Amsterdam, NL, EU
|
|
Back to top |
|
laurin1
Joined: 26 Oct 2014 Posts: 74 Location: Flower Mound, TX
|
Posted: Sat 21 Jul '18 1:10 Post subject: |
|
|
Ok, I got that to load correctly, or so it seems, using ImageMagick-6.9.9-48-Q16-x86-dll, but now I'm getting errors like this:
NoDecodeDelegateForThisImageFormat `TIFF' @ error/constitute.c/ReadImage/504 |
|
Back to top |
|
laurin1
Joined: 26 Oct 2014 Posts: 74 Location: Flower Mound, TX
|
Posted: Sat 21 Jul '18 1:24 Post subject: |
|
|
Ok, I moved all of the DLL file from imagemagick\modules/\coders to the root of the imagemagick folder and that worked. I think I had to do that before.
Is there a recommended way to configure this? I don't want to put multiple ImageMagick folders in my path. |
|
Back to top |
|