Răsfoiți Sursa

echo -> STDOUT STDERR

visuddhinanda 4 ani în urmă
părinte
comite
c4738ca22b

+ 7 - 7
public/app/dict/redis_import_dict.php

@@ -19,7 +19,7 @@ if (PHP_SAPI == "cli") {
 		}
         $redis = redis_connect();
         if ($redis == false) {
-            echo "no redis connect\n";
+            fwrite(STDERR,"no redis connect\n") ;
             exit;
 		}
 		
@@ -36,7 +36,7 @@ if (PHP_SAPI == "cli") {
 				runTask($redis,$taskList[$tableNum],$dir);
 			}
 			else{
-				echo "wrong task number task length is ".count($taskList);
+				fwrite(STDERR, "wrong task number task length is ".count($taskList));
 			}
 		}
     }
@@ -48,7 +48,7 @@ function runTask($redis,$task,$dir){
 	foreach ($task->csv as $csv) {
 		$csvfile = $dir."/".$csv;
 		if (($fp = fopen($csvfile, "r")) !== false) {
-			echo "单词表load {$csvfile}\n";
+			fwrite(STDOUT, "单词表load {$csvfile}\n");
 			$row=0;
 			while (($data = fgetcsv($fp)) !== false) {
 				$row++;
@@ -69,20 +69,20 @@ function runTask($redis,$task,$dir){
 					$redis->hSet($task->rediskey,$data1[$task->keycol],json_encode($new, JSON_UNESCAPED_UNICODE));							
 				}
 				else{
-					echo "列不足够:行:{$row} 列:".count($data1)." 数据:{$data} \n";
+					//echo "列不足够:行:{$row} 列:".count($data1)." 数据:{$data} \n";
 				}
 				$count++;
 				if($count%50000==0){
 					sleep(1);
-					echo $count."\n";
+					fwrite(STDOUT, $count."\n");
 				}
 			}
 			fclose($fp);
 			sleep(1);
-			echo "task : {$task->rediskey}:".$redis->hLen($task->rediskey)."\n";
+			fwrite(STDOUT,  "task : {$task->rediskey}:".$redis->hLen($task->rediskey)."\n");
 			
 		} else {
-			echo "can not open csv file. ";
+			fwrite(STDERR,  "can not open csv file. ".PHP_EOL);
 		}	
 	}
 }

+ 4 - 1
public/app/dict/redis_import_term.php

@@ -39,8 +39,11 @@ if (PHP_SAPI == "cli") {
 				$redis->hSet($rediskey,$word["word"],json_encode($redisWord,JSON_UNESCAPED_UNICODE));
 			}
 		}
+		fwrite(STDOUT,  "all done ".$redis->hLen($rediskey).PHP_EOL);
+	}else{
+		fwrite(STDERR,"redis connect is fail".PHP_EOL);
 	}
-	echo "all done ".$redis->hLen($rediskey);
+	
 }
 
 ?>

+ 1 - 1
public/app/dict/redis_import_user.php

@@ -40,7 +40,7 @@ if (PHP_SAPI == "cli") {
 			}
 		}
 	}
-	echo "all done ".$redis->hLen($rediskey);
+	fwrite(STDOUT,  "all done ".$redis->hLen($rediskey).PHP_EOL);
 }
 
 ?>

+ 5 - 2
public/app/dict/redis_pm_part.php

@@ -5,7 +5,7 @@ require_once __DIR__."/../redis/function.php";
 if (PHP_SAPI == "cli") {
 	$redis = redis_connect();
 	if ($redis != false) {
-		$dbh = new PDO(_DICT_DB_PM_, "", "", array(PDO::ATTR_PERSISTENT => true));
+		$dbh = new PDO(_DICT_DB_PM_, Database["user"], Database["password"], array(PDO::ATTR_PERSISTENT => true));
 		$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 		$query = "SELECT pali,parts from "._TABLE_DICT_PM_." where 1 group by pali";
 		$stmt = $dbh->query($query);
@@ -15,8 +15,11 @@ if (PHP_SAPI == "cli") {
 				$redis->hSet("dict://pm/part",$row["pali"],$row["parts"]);
 			}
 		}
+		fwrite(STDOUT, "all done ".$redis->hLen("dict://pm/part").PHP_EOL);
+	}else{
+		fwrite(STDERR,"redis connect is fail".PHP_EOL);
 	}
-	echo "all done ".$redis->hLen("dict://pm/part");
+	
 }
 
 ?>

+ 1 - 1
public/app/dict/redis_ref_with_mean.php

@@ -16,7 +16,7 @@ if (PHP_SAPI == "cli") {
 			$redis->hSet("dict://ref/has_mean",$row["word"],"1");
 		}
 	}
-	echo "all done ".$redis->hLen("dict://ref/has_mean");
+	fwrite(STDOUT,  "all done ".$redis->hLen("dict://ref/has_mean").PHP_EOL);
 }
 
 ?>

+ 4 - 4
public/app/dict/redis_refresh_first_mean.php

@@ -20,14 +20,14 @@ if (PHP_SAPI == "cli") {
 			print_r($languages);
 			foreach ($languages as $thisLang) {
 				# code...
-				echo "runing $thisLang \n";
+				fwrite(STDOUT,  "runing $thisLang \n");
 				$query = "SELECT word,mean from " . _TABLE_DICT_REF_ . " where language = ? group by word";
 				$stmt = $PDO->prepare($query);
         		$stmt->execute(array($thisLang));
 				while($meaning=$stmt->fetch(PDO::FETCH_ASSOC)){
 					$redis->hSet("ref_first_mean://".$thisLang,$meaning["word"],$meaning["mean"]);
 				}
-				echo $thisLang.":".$redis->hLen("ref_first_mean://".$thisLang)."\n";
+				fwrite(STDOUT,  $thisLang.":".$redis->hLen("ref_first_mean://".$thisLang)."\n");
 			}
 
 			$query = "SELECT word,mean from " . _TABLE_DICT_REF_ . " where 1 group by word";
@@ -36,11 +36,11 @@ if (PHP_SAPI == "cli") {
 			while($meaning=$stmt->fetch(PDO::FETCH_ASSOC)){
 				$redis->hSet("ref_first_mean://com",$meaning["word"],$meaning["mean"]);
 			}
-			echo "com:".$redis->hLen("ref_first_mean://com")."\n";
+			fwrite(STDOUT,  "com:".$redis->hLen("ref_first_mean://com")."\n");
 		}
 	}
 	else{
-		echo "no redis server";
+		fwrite(STDERR,  "no redis server");
 	}
 
 }

+ 4 - 2
public/app/dict/redis_sys_rgl_part.php

@@ -6,7 +6,7 @@ if (PHP_SAPI == "cli" || isset($_COOKIE["userid"]))
 {
 	$redis = redis_connect();
 	if ($redis != false) {
-		$dbh = new PDO(_DICT_DB_REGULAR_, "", "", array(PDO::ATTR_PERSISTENT => true));
+		$dbh = new PDO(_DICT_DB_REGULAR_, Database["user"], Database["password"], array(PDO::ATTR_PERSISTENT => true));
 		$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 		
 		$query = "select * from (SELECT pali,parts from "._TABLE_DICT_REGULAR_." where 1  order by confidence DESC ) where 1 group by pali";
@@ -15,8 +15,10 @@ if (PHP_SAPI == "cli" || isset($_COOKIE["userid"]))
 			# code...
 			$redis->hSet("dict://regular/part",$row["pali"],$row["parts"]);
 		}
+		fwrite(STDOUT,  "all done ".$redis->hLen("dict://regular/part").PHP_EOL);
+	}else{
+		fwrite(STDERR,"redis connect is fail".PHP_EOL);
 	}
-	echo "all done ".$redis->hLen("dict://regular/part");
 }
 
 ?>

+ 6 - 6
public/app/pali_sent/redis_upgrade_pali_sent.php

@@ -21,9 +21,9 @@ if (isset($argv[1])) {
 				$count += $deleted;
 			}
 			
-			echo "delete ok ".$count;			
+			fwrite(STDOUT,"delete ok ".$count.PHP_EOL) ;			
 		}else{
-			echo "redis connect error ".PHP_EOL;			
+			fwrite(STDERR, "redis connect error ".PHP_EOL);			
 
 		}
     }
@@ -50,11 +50,11 @@ if (isset($argv[1])) {
                 $stringSize = 0;  
 			}
 			if($count%10000==0){
-				echo $count . "-".$sent["book"] . "_" . $sent["paragraph"] . "\n";
+				fwrite(STDOUT, $count . "-".$sent["book"] . "_" . $sent["paragraph"] . "\n");
 			}
 			$result = $redis->hSet('pali://sent/' . $sent["book"] . "_" . $sent["paragraph"] . "_" . $sent["begin"] . "_" . $sent["end"], "pali", $sent["html"]);
 			if($result===FALSE){
-				echo "hSet error \n";
+				fwrite(STDERR, "hSet error \n");
 			}
 			$result = $redis->hSet('pali://sent/' . $sent["book"] . "_" . $sent["paragraph"] . "_" . $sent["begin"] . "_" . $sent["end"], "id", $sent["id"]);	
 
@@ -69,8 +69,8 @@ if (isset($argv[1])) {
 			}
 			$result = $redis->hSet('pali://sent/' . $sent["book"] . "_" . $sent["paragraph"] . "_" . $sent["begin"] . "_" . $sent["end"], "sim_count", $pali_sim);			
         }
-        echo "完成 ". count($redis->keys("pali://sent/*"));
+        fwrite(STDOUT, "完成 ". count($redis->keys("pali://sent/*")).PHP_EOL);
     } else {
-        echo "连接redis失败";
+        fwrite(STDERR, "连接redis失败".PHP_EOL);
     }
 }