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
Replaced time() with $_SERVER['REQUEST_TIME'] #944
Conversation
http://php.net/manual/en/reserved.variables.server.php "REQUEST_TIME": The timestamp of the start of the request. Available since PHP 5.1.0. It is float with microseconds since PHP 5.4.0. Does this pull request give a problem with PHP 5.4? |
Regarding to the changelog of 5.4:
But I have no possibility to test this with PHP 5.4 :/ I could add a floor to it, but I guess it will vanish the performance improvement. :/ |
In versions before 5.4 the request_time is a int, but from PHP 5.4 it will be a float (eg. 1326987371.123123) then time() is maybe better to use... Maybe define a time() somewhere in the code (index.php), so you don't have to call time() multiple times? |
Yes, I got this the first time. Basically PHP 5.4 $_SERVER['REQUEST_TIME'] has microtime(TRUE); as value. I tested
which works perfectly fine. I ran also some other test, which had no problems with the float variant.
|
This can only break something. |
I will test this further on the weekend, probably with a PHP 5.4 RC version and make the appropiate additions if necessary or drop the changes completely. |
Haha, the new PHP 5.4 RC6 release (yesterday), https://svn.php.net/repository/php/php-src/tags/php_5_4_0RC6/NEWS _Restoring So your pull request should work ;-) |
oh oops, I could have re-opened ... :/ sorry, I am new to this. =) |
What about using $this->input->server('REQUEST_TIME') for each $_SERVER['REQUEST_TIME'] ? |
Well, this would make sense if the client actually had access to this global. But it's filled by the php process with time() on the beginning of the request processing. |
@flashover The point is to not have the overhead of calling a function and use a variable instead - calling a custom method (that reads from this very same variable) doesn't make any sense. I still think this is not needed though. I'd usually do crazy stuff to optimize for speed, but |
If something or someone is modifying $_SERVER in your app, you will have other problems than performance. :) So, this pull request is rejected then? |
Indeed, but using |
I am listening guys, I was just waiting for you two to hash out your argument as I am on the fence. So it seems, this change will work in 5.1-5.3, but COULD cause problems in 5.4 due to the int/float change. Test it, does it cause problems. If so, typecasting for the win? @narbg I don't think we need to worry about security here, nobody is going to be messing around with the $_SERVER variable and if they are they deserve any confusion they get. I also don't think this change is about speed differences of variable access over function calls, it is about reporting the time more accurately on slow page calls. |
Um, no - the int/float issue only exist in beta and some of the RC versions for PHP 5.4. This is a quote from the changelog for 5.4.0 RC6:
IMO, time accuracy is a completely different argument, as in some cases it might be more convenient to have records for when did a certain process take place instead of when the request was initiated. Actually, now that you've mentioned that ... most of the changed libraries are only useful in web applications, but e.g. the DB utility class could be used via CLI. Let's say we have a daemon like script that does database backups every n hours (it's stupid, because that should be done via crontab, but still possible and in this case - just an example). And here's what happens:
A similar issue can be expected with the ZIP and probably Image manipulation libraries. |
Seems valid. I'll be honest, I don't really care either way about this So far Andrey seems to have the best reasoning, so "Against" is winning.
|
Because of the accuracy thing I left out the Date Helper in the pull request. But usually on high traffic sites you will need 'minor' win this change is providing. @narfbg We could leave out the DB_utility and Calendar, if this is the issue. :) |
If it's not used in DB utility, Image_lib and Zip (or in other words - if it's only applied to HTTP-only libraries) - I'm OK with it. Indeed it's more a matter of preference there and I'm probably way too concerned about security at times. :) |
@TwoBee Seems like we replied at the same time. :) Calendar generates HTML code and is useless in the CLI, so it's good in there. |
As I mentioned before, if someone messes with your $_SERVER you really have other (more serious) problems. Yes, I agree on a CLI level this could lead to a certain inaccurancy. I can revoke it or we discuss which measure are useful and doing just them instead of all. I would then apply this changes only to my system. :) |
I will update the repository later this week to the changes we discussed. |
What's the status @TwoBee ? |
I will update the request within the next two days. :) |
Radical thought here: Why not just have in the constants config file <?php
define('REQUEST_TIME', time()); then use that? |
Probably because a variable with the same value already exists? |
The variable exists in the $_SERVER super global. Which as Phi pointed The suggestion I'm making is to create a define at the start of the On the topic of needing exact second correctness in the DB etc. the --Ryan Neufeld BSc CIS On Fri, Mar 30, 2012 at 7:34 AM, Andrey Andreev
|
@ryanneufeld Still, it's missing the whole point here. |
@it-can Sorry, got a bit tied up in the last time :( |
@ryanneufeld Actually, it was me pointing out all of the cons against using |
@TwoBee Well, perhaps I'm missing the point. But I've seen two arguments here. What is the point then? |
@ryanneufeld We discussed this topic more than enough, I will revert the changes as discussed with @narfbg . Then it will be either merged or not. |
I finally applied the changes, do I need anything else to do? :) |
Conflicts: system/libraries/Session.php
So far, so good. But why are file permissions for the cache drivers changed? |
I can revert the examples, too. Sorry about the permissions, I guess my VMWARE settings are responsible for this. I try to fix it. :( |
As discussed in 7bb95df#commitcomment-881705
Replacement of time() calls with $_SERVER['REQUEST_TIME'] , I left out the date_helper for now.