Not sure why this works for you at all - maybe different php version.
18 $data=openssl_random_pseudo_bytes(1048576,false);
I'm guessing you are trying to turn "strong encryption" off to conserve resources... but that's not what that parameter does (the wording of the documentation is a bit confusing there - for php7 at least: it's not a setting, just a variable that will tell you afterwards, whether the string you got is suitable for use in encryption etc or if your openssl is too old/broken)...