LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-05-2016, 11:10 AM   #1
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
C time() vs php $_SERVER['REQUEST_TIME']


In a php script on my server, if i use $_SERVER['REQUEST_TIME'] to get the system clock time, and from that script execute a binary on the same server written in C which uses the time() function, will both functions always return the same clock value? That is to say, will the return value of time() in the C module always be within a few milliseconds of the $_SERVER['REQUEST_TIME'] value in the php script?

Am thinking perhaps one or the other function may be affected by an environment variable to adjust according to a time zone or daylight savings?
 
Old 10-05-2016, 12:39 PM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
I think it can vary more if you have a slow posting/uploading client.

Quote:
'REQUEST_TIME'
The timestamp of the start of the request. Available since PHP 5.1.0.
This number is from the web server. If it's a slow POST, daylight time changes while transfering data, you can get very different numbers. You can use time() in PHP to get the time when the function is called.
 
Old 10-05-2016, 01:51 PM   #3
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490

Original Poster
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
Quote:
Originally Posted by Guttorm View Post
'REQUEST_TIME'
The timestamp of the start of the request. Available since PHP 5.1.0.
.
.
.
You can use time() in PHP to get the time when the function is called.
So, 'the time when the function is called' is the time when the php script is loaded? And the 'start of the request' is when the script executes the particular line of code? Or vice-versa?

In this php script
Code:
<?php
.
.
some php code
.
.
.
$req_time = $_SERVER['REQUEST_TIME'];
$ptime = time();
.
.
some more php code
.
.
.
$ctime = exec(c_binary_which calls_time);
.
.
?>
$ptime might be a slightly smaller (earlier) time value than $req_time? And both might be smaller than $ctime?

Last edited by dogpatch; 10-05-2016 at 01:53 PM.
 
Old 10-05-2016, 02:52 PM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
php time() and c time() get time in second, so if php code execution duration between both calls is less than one second (likely), $ptime and $ctime should have the same value, and same value as $req_time (no executed code between $req_time and $ptime settings)
 
  


Reply

Tags
'c', php, time



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP $_SERVER['HTTP_REFERER'] returns previous url? ldp Programming 6 05-11-2018 02:14 AM
[PHP] How to make a path $_SERVER['DOCUMENT_ROOT'] plus one more dir? Mr. Alex Programming 2 04-23-2012 04:51 AM
Apache/PHP, Get real IP, not $_SERVER['REMOTE_ADDR']? Shioni Programming 3 01-02-2007 10:44 AM
$_SERVER['QUERY_STRING']-php Manashi Programming 10 04-20-2006 05:01 PM
php $_SERVER value missing dinges Programming 6 12-23-2004 02:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration