CodeIgniter Forums
PHP version check in index.php file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: PHP version check in index.php file (/showthread.php?tid=72062)



PHP version check in index.php file - Pertti - 10-31-2018

I was going through the code in latest repo, and I do have question about public/index.php file.

PHP Code:
// Valid PHP Version?
$minPHPVersion '7.1';
if (
phpversion() < $minPHPVersion)
{
    die(
"Your PHP version must be {$minPHPVersion} or higher to run CodeIgniter. Current version: " phpversion());
}
unset(
$minPHPVersion); 

It probably doesn't add more than fraction of a second to execution time, but I wonder if there's better place for this and other similar "compatibility" checks?

I could of course easily remove it myself, but because so much initial CI set up happens in index.php file, it feels sacred and could potentially change with future releases.

One of Rasmus Lerdorf talks comes in mind, where he showed frustration that frameworks do a lot of repeat work for every request even when there's no chance PHP version, or in his talk, DB engine, would change between two requests.

Maybe that check be part of vanilla non-CI core standalone script that checks specs and libraries?


RE: PHP version check in index.php file - Paradinight - 10-31-2018

(10-31-2018, 07:47 AM)Pertti Wrote: I was going through the code in latest repo, and I do have question about public/index.php file.

PHP Code:
// Valid PHP Version?
$minPHPVersion '7.1';
if (
phpversion() < $minPHPVersion)
{
 die(
"Your PHP version must be {$minPHPVersion} or higher to run CodeIgniter. Current version: " phpversion());
}
unset(
$minPHPVersion); 

It probably doesn't add more than fraction of a second to execution time, but I wonder if there's better place for this and other similar "compatibility" checks?

I could of course easily remove it myself, but because so much initial CI set up happens in index.php file, it feels sacred and could potentially change with future releases.

One of Rasmus Lerdorf talks comes in mind, where he showed frustration that frameworks do a lot of repeat work for every request even when there's no chance PHP version, or in his talk, DB engine, would change between two requests.

Maybe that check be part of vanilla non-CI core standalone script that checks specs and libraries?

Yes, it is unnecessary.


RE: PHP version check in index.php file - Pertti - 10-31-2018

Just browsing through some code, so don't know if it's better solution just yet, but it wouldn't be so bad if it was on every spark CLI request.

Or maybe spark utility command on it's own. There's nothing about spark in documentation, but I assume that's the main way to deal with framework from CLI.

Or if going in from browser route, displays errors, because then error already happened and we're displaying, so we know something went wrong, let's go through couple of potential issues that we can check and display that as part of hey your versions don't match.


RE: PHP version check in index.php file - kilishan - 10-31-2018

Yes, it's unnecessary as far as the code goes, and can probably be removed as time goes on. it is in there currently only because there's a significant jump in the version requirement from CI3 to CI4 and we had quite a few questions that were simply answered by "Make sure your version is 7.1 or higher". This is there to save us answering that question repeatedly.

I would not be opposed to removing it in RC versions, but for now, it's a definitely time-saver.


RE: PHP version check in index.php file - Pertti - 11-01-2018

Now that I know your reasons, definitely can understand why it's in there for now.

On flip side, CI has always been about being leaner and faster than competition, hence my OP, hope you don't mind.


RE: PHP version check in index.php file - kilishan - 11-01-2018

Nope - don't mind at all, Pertti. Though, now that I'm thinking of it, I believe the version check exists in older versions, also, just in a different place.


RE: PHP version check in index.php file - Pertti - 11-01-2018

And it's potentially a premature optimisation from my part.

Did a bit benchmarking with stand alone test script, and that check, including assigning and unsetting min PHP version, takes just 0.000005 seconds.