2011-01-24 52 views
1

好了一個相當奇怪的問題在這裏(或者也許不是)來更新MySQL的使用curl時捲曲吐出JSON

我試圖拉鳴叫出在這裏使用捲曲嘰嘰喳喳的是命令

curl http://stream.twitter.com/1/statuses/filter.json?track=XXhashtagXX -XXuserXX:XXpassXX 

每個地方都有一個x,它是一個像twitter用戶名和密碼這樣的變量的地方,也是尋找hashtag的地方。

這是使用twitter restful api,每次更改都會提醒您的腳本。

在控制檯中,這個curl命令可以很好地工作,但現在我只需要輸出並將其保存到我的mysql表中。

任何幫助將不勝感激。

+0

你的困難在哪裏?你的腳本不能讀取輸出文件,或者你不知道如何將東西插入到數據庫中? – mario 2011-01-24 20:32:03

回答

1

IRL哥們。這就是你想要的東西。

CHMOD一個+ X watch_twitter.sh ./watch_twitter.sh

SH watch_twitter.sh

watch_twitter.sh

#!/usr/bin/sh 
nohup curl http://stream.twitter.com/1/statuses/filter.json?track=hashtag -uusername:password\!\! -o test.txt -N & 
nohup php watch_test.php & 
exit 

watch_test.php

<?php 
while(1){ 
     echo "."; 
     $data = file_get_contents('test.txt'); 
     if($data){ 
       file_put_contents('test.txt',""); 
       $dataarry = explode("\n",$data); 
       foreach($dataarry as $data){ 
         print_r(json_decode(trim($data))); 
       } 
       echo "FOUND SOMETHING!"; 
     } 
     sleep(1); 
} 
print_r($data); 
?>