Welcome Guest, Not a member yet? Register   Sign In
PHP version check in index.php file
#1

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?
Reply
#2

(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.
Reply
#3

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.
Reply
#4

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.
Reply
#5

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.
Reply
#6

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.
Reply
#7

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB