将新值推送到mongodb不能在PHP中运行多进程

时间:2015-10-27 10:18:48

标签: php mongodb

我正在编写一个测试程序: 200个进程将10000条记录写入mongodb中的一个集合 记录应附加到集合的末尾,因此我按照示例[push new value to mongodb inner array][1] - mongodb/php

下面是我的代码:

$data = $memcache->get('data');
$m = new MongoClient();
$db = $m->record_test;
$collection = $db->record;
$time = $db->record_time;

for ($i=0; $i < 10000; $i++) { 
    $time_start = microtime_float();

    $collection->insert($data);

    $time_end = microtime_float();
    $run_time = $time_end - $time_start;

    $newdata = array('$push' => array('time' => $run_time));
    $time->update(array("time" => 0 ), $newdata);
}

$ data的内容:     排列 (     [0] =&gt;排列         (             [Register_Name] =&gt; MGC_IP             [Register_Value] =&gt; 192.168.1.9             [Register_Unit] =&gt;             [Device_Name] =&gt;这个             [R_W] =&gt;         )

[1] => Array
    (
        [Register_Name] => MGC_SW_VERSION
        [Register_Value] => 0.9.15.1022_SPI  
        [Register_Unit] =>  
        [Device_Name] => this
        [R_W] =>  R
    )

[2] => Array
    (
        [Register_Name] => MGC_FW_VERSION
        [Register_Value] => 0.1.15.915.1     
        [Register_Unit] =>  
        [Device_Name] => this
        [R_W] =>  R
    )

[3] => Array
    (
        [Register_Name] => MGC_ZONE_ID
        [Register_Value] => zone0    
        [Register_Unit] =>  
        [Device_Name] => this
        [R_W] =>  R
    )

[4] => Array
    (
        [Register_Name] => MGC_DEVICE_ID
        [Register_Value] => mgc0     
        [Register_Unit] =>  
        [Device_Name] => this
        [R_W] =>  R
    )

[5] => Array
    (
        [Register_Name] => MGC_SYS_TIME
        [Register_Value] => 2015/10/27 10:12:04  
        [Register_Unit] =>  
        [Device_Name] => this
        [R_W] =>  R
    )

[6] => Array
    (
        [Register_Name] => MGC_P1_STATUS
        [Register_Value] => Access fails     
        [Register_Unit] =>  
        [Device_Name] => this
        [R_W] =>  R
    )

[7] => Array
    (
        [Register_Name] => MGC_P2_STATUS
        [Register_Value] => Not configured   
        [Register_Unit] =>  
        [Device_Name] => this
        [R_W] =>  R
    )

在完成10000条记录之后,我收集的内容一无所获!我使用这个示例代码来检查我的结果:

$m = new MongoClient();
echo "Connection to database successfully.<br>";
$db = $m->record_test;
echo "Database record_test selected.<br>";
$time = $db->record_time;
echo "Collection record selected succsessfully.<br>";
echo $time->count(), "\n";

$cursor = $time->find();
var_dump(iterator_to_array($cursor));

输出:

Connection to database successfully.
Database record_test selected.
Collection record selected succsessfully.
0

有人可以帮助我吗?为什么我的var_dump()什么都没有?我在mongodb和PHP中真的很新:&#39;(

0 个答案:

没有答案