This is queryed from a database (the row is set to current_timestamp) and it seems to be outputing 2010-05-27 10:18:38 I need to convert this to a timestamp and then get three seconds ahead of that time so I can compare it to another timestamp. How would I do this? Thank you.
$date = new DateTime('2010-05-27 10:18:38'); $timestamp = $date->getTimestamp(); $newTimestamp = $timestamp + 3; $newDate = new DateTime(); $newDate->setTimestamp($newTimestamp); PHP:
<?php $date = '2010-05-27 10:18:38'; //convert $date to a timestamp... $date_to_timestamp = strtotime($date); //add 3... $new_date = $date_to_timestamp + 3; //output the new date... echo $new_date; ?> PHP:
Thanks. Is there anyway to create a variable which is shared by everyone using my .php script? Kind of like session but with everyone?
It's for a function which must run constantly, like a cron job, but the only difference is that it must only run if people are using one of my .php scripts. The function will delete rows from a database every 5 seconds. The problem is that I only want it to do this if there are people using a different .php script. Hope I explained it okay. Thanks!
if you want data shared between multiple users, use a tabel in your database, store the variable in it, and in your script retrieve it everytime, check it against your conditions and update it if that's the case
I was thinking about doing that but I was wondering if PHP had a faster better way to do that function?
Temp file storage may be easier //$temp - variable you want to store file_put_contents('tempFileName', serialize($temp)); //when you want to read the temp file from any other file $temp = unserialize(@file_get_contents('tempFileName')); PHP:
You may want to skip that php parsed calculations by just requesting what you really want SQL select UNIX_TIMESTAMP(date_add(now(), interval 3 second)) Code (markup): Regards
I would use APC or memcached to store a persistent variable. If you're not using APC it's a good idea to install it anyway. apc_add('foo', $bar); apc_fetch('foo');