I have this code inside of a exit hook in a custom module:
$diff = round(((microtime(true)-$script_start_time)*1000));
watchdog('thaty', $diff);
if(variable_get('thingy', 0) == 1) {
$data = array(
'q'=>$_GET['q'],
'memory'=>memory_get_peak_usage(),
'execution_time'=>$diff
);
db_query('INSERT INTO {blah} (q,memory,dt,execution_time) VALUES (\'%s\',%b,UNIX_TIMESTAMP(),%b)',$data);
}
The value of $diff will occasionally consistently get saved in the database as 2147483647, which is the overflow value for an INT, I believe, in PHP. When I log the value via watchdog I can confirm that it does not get set to 2147483647, but the real value, which is a three digit whole number.
Typical values (confirmed from logging):
- 708
- 408
- 413
The execution_time column is int(11).
I can't seem to find the source of this issue. Things I've tried:
- Using %d instead of %b for the value
- Assigning $diff to a new an INT variable
- Checking for this wrong value pre-insert
- Confirming the value of $diff is not too large for an INT in PHP
- Tried using %n, re: http://www.lullabot.com/articles/drupocalypse-now-or-dangerous-integer-handling-drupal-write-record