Php microtime()不能在活动站点上工作.寻找解决办法


Php microtime() is not working on live site. Looking for workaround

我在Windows上有Zend Server 6.3和Php 5.4。这个系统运行得很好。现在我将代码移动到live站点,它在Ubuntu服务器上运行Php 5.3.29与DirectAdmin。所有其他网站都运行良好。但是我现在的网站给我这个错误(这个网站是在WordPress 4.3上):

Warning: mysql_connect(): Headers and client library minor version mismatch.
Headers:50541 Library:50623 in /home/cheapauto/domains/*DOMAIN*/public_html/wp-includes/wp-db.php on line 1482
Parse error: syntax error, unexpected '[' in /home/*USER*/domains/*DOMAIN*/public_html/wp-content/plugins/*MY-PLUGIN*/includes/final.class.NRSBooking.php on line 101 

命令行如下:

$now = explode(' ', microtime())[1];

我的整个插件函数是这样的:

private function getIncrementalHash($length = 5)
{
    //$charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    $charset = "ABCDEFGHIJKLMNPRSTUVYZ"; // fits LT & EN, O is skipped to similarity to Zero
    $charsetLength = strlen($charset);
    $result = '';
    $now = explode(' ', microtime())[1];
    while ($now >= $charsetLength)
    {
        $i = $now % $charsetLength;
        $result = $charset[$i] . $result;
        $now /= $charsetLength;
    }
    return substr($result, -$length);
}

有什么想法如何使它在现场工作吗?

根据Php参考http://php.net/manual/en/function.microtime.php它说:

microtime()返回当前Unix时间戳,单位为微秒。这函数仅在支持的操作系统上可用。gettimeofday()系统调用。

我使用该函数生成唯一的新预订代码:

$newBookingCode = "R".$validNextMySQLInsertId."A".$this->getIncrementalHash(5);

谢谢!

数组解引用,即从函数中获取返回数组的结果,如:

$now = explode(' ', microtime())[1];

php5.4

开始可用

对于php5.3及旧版本:

$now = explode(' ', microtime());
$now = $now[1];