English 中文(简体)
多个网站
原标题:multiple php function instances
  • 时间:2009-12-11 10:25:23
  •  标签:
  • php
  • mysql

I ve got a function which calculates some data from a table, a put s it into another, it takes a while for the whole process, about 30 mins or something like that. The function calculates statistics for each day for a couple of months period, but after like 10 days, it starts another thread while continuing another one, and then another one, and another, so i get a table full of random crap in the end.

为什么在另一个未完成的时候,它会开始另一个职能的例子?

该职能:

function build_fill_array() {

$sql = db_fetch_object(db_query("SELECT min(timestamp) as min FROM {accesslog}"));
$nids = db_query("SELECT nid FROM {node} WHERE type= raamat ");
while($nid_array = db_fetch_array($nids)) {
    $nid[] = $nid_array[ nid ];
}
$start_ts = $sql->min;
$end_ts = mktime(0,0,0, date( m ), date( d ), date( Y ));
$start_ts = mktime(0,0,0, date( m , $start_ts), date( d , $start_ts), date( Y , $start_ts));

while($start_ts != $end_ts) {
    $day = date( d.m.Y , $start_ts);
    $range_from = mktime(0,0,0, date( m , $start_ts), date( d , $start_ts), date( Y , $start_ts));
    $range_to = mktime(23,59,59, date( m , $start_ts), date( d , $start_ts), date( Y , $start_ts));
    foreach($nid as $n) {
    $results = db_fetch_object(db_query("SELECT count(hostname) as total, count(distinct hostname) as visits FROM {accesslog} WHERE timestamp BETWEEN %d AND %d AND path =  node/%d ", $range_from, $range_to, $n));
    $sql_insert = "INSERT INTO {statistics_view} (`id`, `nid`, `total`, `unique`, `timestamp`, `date`) VALUES (NULL, $n, $results->total, $results->visits, ".mktime().",  $day );";
    db_query($sql_insert); 
  }


    $start_ts = mktime(0,0,0, date( m , $start_ts), date( d , $start_ts)+1, date( Y , $start_ts));
}

}

Edit:在桌子上不要忘记{},而是一纸空文。

问题回答

为什么在另一个未完成的时候,它会开始另一个职能的例子?

你们应该看看职能是什么地方,而不是职能本身。

替换

while($start_ts != $end_ts) {

while($start_ts <= $end_ts) {




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签