看板 PHP 關於我們 聯絡資訊
手邊的程式希望能讓使用者在網頁上輸入參數, 然後利用R來繪出統計圖表和做一些統計運算 再把結果傳回到PHP來呈現 目前已經測試過: 1. PHP把參數傳給R,並讓R根據這個參數來繪圖,再由PHP顯示 <- ok 2. R 連接資料庫,取出資料繪圖 <- ok PHP 連結資料庫,取出資料做成表格 <- ok 但是PHP呼叫R,由R根據參數到資料庫取資料繪圖之後就沒下文了 程式擷取如下 PHP部分 <?php // student_enroll.php echo "<form action='student_enroll.php' method='get'>"; echo "近<input type='text' value='3' name='N' />來的學生入學人數分析"; echo "<br><input type='submit' />"; echo "</form>"; if(isset($_GET['N'])) { $N = $_GET['N']; // execute R script from shell // this will save a plot at temp.png to the filesystem $str = '"C:\Program Files\R\R-3.2.3\bin\Rscript"' . ' .\student_enroll.R' . " $N"; $data = shell_exec($str); echo $data; // return image tag $nocache = rand(); echo("<img src='temp.png?$nocache' />"); } ?> R的部分 library(RODBC) library(MASS) library(ggplot2) library(tidyr) #從PHP取得參數 args <- commandArgs(TRUE) set.year <- strtoi(args[1]) print(set.year) #取得現在是哪一年並轉換成中國年 this.year <- strtoi(substring(Sys.time(), 0, 4)) - 1911 #設定資料庫連結 print(5) odbcChannel <- odbcDriverConnect(connection="Driver={SQL Server};server=127.0.0.1\\servername;database=database_name; trusted_connection=yes;uid=uid;pwd=pwd") print(6) query.result <- sqlFetch(odbcChannel, "table_name") print(7) print(query.result) odbcClose(odbcChannel) 紅字以下都沒有順利執行完 現在有質疑是否PHP等待R存取資料庫的時間太久了 因為不知道怎麼讓PHP顯示錯誤訊息 只能用這種土法煉鋼法得知程式執行到哪一行之後沒有繼續 盼望有人可以解惑阿,不然已經卡在這個步驟一個多星期了 感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.159.193 ※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1452155247.A.DBF.html
Peruheru: 雖然跟你的錯誤無關XD 01/07 17:36
Peruheru: 回到問題,你遇到的問題可能是伺服器逾時 01/07 17:37
Peruheru: 查詢超過30秒就會被當成執行失敗,這數字好像可以調 01/07 17:38
Peruheru: 根本之道還是得加速查詢才行 01/07 17:40
MOONRAKER: php叫R開始算 算好放在/tmp/res{pid}底下 01/07 20:58
MOONRAKER: 隔30秒再用js叫另一隻php去把它打開 01/07 20:59
Schematic: 請問哪邊可以調整30秒的等待時間呢?我想先試著調整這邊 01/08 09:11
xdraculax: set_time_limit 01/08 11:59
Schematic: 感謝所有的回答,繼續測試中 01/08 12:02
Schematic: 已經更改過系統的等待時間,也試過設定執行時間 01/08 12:58
Schematic: 結果都還是一樣>"< 01/08 12:58