Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
05-07-2011, 09:09 PM,
Post: #1
PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
aku godek2 google petang tadi cari PHP function untuk listen http push dgn php, tapi tak jumpa. maka, terhasillah code dibawah. diadaptasi daripada xmlhttprequest ajax yg digunakan oleh shoutbox tbd tapi yang ini menggunakan PHP. Code ni la yg aku share dengan abe johnburn petang tadi tu (bagi yg perasan kat shoutbox tu Big Grin

Apa fungsi code ni? - Dia akan listen/tunggu data daripada server (shoutbox tbd), Kalau server tak bagi respon (tak ada org chat), dia tunggu je sampai ada. Lepas server respon, data diperolehi, koneksen tadi akan terhapus dan dia akan ulang balik, iaitu listen/tunggu data dari server.

----------------------------------
Sekadar pemberitahuan kepada yang masih tak tahu. Shoutbox tbd menggunakan teknologi long polling/comet. Ia berbeza dengan shoutbox biasa yang akan refresh setiap beberapa saat (request data dari server). Shoutbox tbd ni, client akan tunggu server yang bagi data. Proses yg bertentangan dari pada biasa. Teknologi yang sama macam digunakan oleh facebook.
Rujukan:-
http://en.wikipedia.org/wiki/Push_technology
http://en.wikipedia.org/wiki/Comet_%28programming%29
----------------------------------

PHP Code:
set_time_limit(0);

function 
httpHeader($host) {
    
$out "GET /sub?id=tbdmy HTTP/1.1\r\n";
    
$out .= "Host:    {$host}\r\n";
    
//$out .= "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0\r\n";
    //$out .= "Accept:    text/plain, */*; q=0.01\r\n";
    //$out .= "Accept-Language:    en-us,en;q=0.5\r\n";
    //$out .= "Accept-Encoding: gzip, deflate\r\n";
    //$out .= "Accept-Charset:    ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
    
$out .= "Connection:    keep-alive\r\n";
    
$out .= "X-Requested-With:    XMLHttpRequest\r\n";
    
$out .= "If-None-Match:    0\r\n";
    
$out .= "If-Modified-Since:    ".gmdate("r"time())."\r\n\r\n";
    return 
$out;
}

function 
listen($host) {
    
$return "";
    
$h explode(":"$host);
    
$socket fsockopen($h[0], $h[1]);

    if (!
$socket) {
        echo 
"error\n";
    } else {   
        
fwrite($sockethttpHeader($host));

        if (
$o fread($socket8192)) {
            
$data explode ("\r\n\r\n"$o);
            
//echo $data[1]."\n"; // <-- return data
            
$data json_decode($data[1]);
            echo 
strip_tags($data->uname.": ".$data->shout_msg)."\n";
        }

        
fclose($socket);
        
listen($host);
    }
}

listen("124.217.247.173:8081"); 

Screenshot:
[Image: 1773987086demo.jpg]
[Image: GteM3.png]
Reply
05-07-2011, 09:52 PM,
Post: #2
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
[Image: 265131_237379852946983_100000249094165_9...7403_n.jpg]
love u
[Image: bot.gif]

PHP Code:
printf(“Goodbye world \n”); 
Reply
05-07-2011, 09:53 PM,
Post: #3
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
(05-07-2011, 09:52 PM)saifulfaizan Wrote: [Image: 265131_237379852946983_100000249094165_9...7403_n.jpg]

apa yg anda cuba sampaikan? Smile

[Image: GteM3.png]
Reply
05-07-2011, 09:57 PM,
Post: #4
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
(05-07-2011, 09:53 PM)suhz Wrote:
(05-07-2011, 09:52 PM)saifulfaizan Wrote: [Image: 265131_237379852946983_100000249094165_9...7403_n.jpg]

apa yg anda cuba sampaikan? Smile

lebih kurang same GayFace
love u
[Image: bot.gif]

PHP Code:
printf(“Goodbye world \n”); 
Reply
05-07-2011, 09:58 PM,
Post: #5
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
(05-07-2011, 09:57 PM)saifulfaizan Wrote:
(05-07-2011, 09:53 PM)suhz Wrote:
(05-07-2011, 09:52 PM)saifulfaizan Wrote: [Image: 265131_237379852946983_100000249094165_9...7403_n.jpg]

apa yg anda cuba sampaikan? Smile

lebih kurang same GayFace

tak sama la..

push & pull adalah perkara yg berbeza.
[Image: GteM3.png]
Reply
05-07-2011, 10:01 PM,
Post: #6
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
patut la test2 tadi .... nice tuan forum +rape informasi berguna nie
love u
[Image: bot.gif]

PHP Code:
printf(“Goodbye world \n”); 
Reply
05-07-2011, 10:09 PM,
Post: #7
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
(05-07-2011, 10:01 PM)saifulfaizan Wrote: patut la test2 tadi .... nice tuan forum +rape informasi berguna nie

yg ko buat tu. dia baca daripada page ni kan http://w3.tbd.my/index.php?action=full_shoutbox. dia akan request page tu, then baru dpt baca chat2.
Client --> WebServer --> Client

berbeza dgn yg push ni..
dia request skali, then dia biar je connection antara client dan server sentiasa open sampaila server bg data tu.
Client <--> Push Server <-- WebServer

GayFaceGayFaceGayFace
[Image: GteM3.png]
Reply
06-07-2011, 06:02 AM,
Post: #8
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
nice boleh apply dlm bot ion ni ;d ;d
puas sudah menanam ubi, nenas juga dibeli orang, puas sudah aku berbakti, pengganas juga dipandang orang

Quote:A true warrior need blood on his sword; A true pirate never afraid to sail the red sea.
Reply
06-07-2011, 07:39 AM,
Post: #9
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
ni hasilnye ;d ;d
Spoiler:
[Image: mh7Be.png]
puas sudah menanam ubi, nenas juga dibeli orang, puas sudah aku berbakti, pengganas juga dipandang orang

Quote:A true warrior need blood on his sword; A true pirate never afraid to sail the red sea.
Reply
06-07-2011, 08:07 AM,
Post: #10
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
wow...nice suhz..benda ni la sos tiram..hahaha.. +rep Big Grin
Reply
06-07-2011, 08:08 AM,
Post: #11
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
(06-07-2011, 07:39 AM)Ahlspiess Wrote: ni hasilnye ;d ;d
Spoiler:
[Image: mh7Be.png]

mohon share sos nya.. PM Big Grin
[Image: GteM3.png]
Reply
06-07-2011, 08:30 AM,
Post: #12
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
(06-07-2011, 07:39 AM)Ahlspiess Wrote: ni hasilnye ;d ;d
Spoiler:
[Image: mh7Be.png]

lol aku igt dlm satu console ja
tu aku pelik ko ckp smlm GayFace
[̲̅ə̲̅٨̲̅٥̲̅٦̲̅]
i ℓ٥ﻻ ﻉ√٥υ F٥rﻉ√ﻉr ღ
|_|0|_|
|_|_|0|
|0|0|0|
http://jonhburn2.freehostia.com/lol.txt
Reply
06-07-2011, 09:04 AM,
Post: #13
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
(06-07-2011, 08:30 AM)johnburn Wrote:
(06-07-2011, 07:39 AM)Ahlspiess Wrote: ni hasilnye ;d ;d
Spoiler:
[Image: mh7Be.png]

lol aku igt dlm satu console ja
tu aku pelik ko ckp smlm GayFace

boleh buat dlm satu console, tapi linux onli, dgn pcntl extension ;d
puas sudah menanam ubi, nenas juga dibeli orang, puas sudah aku berbakti, pengganas juga dipandang orang

Quote:A true warrior need blood on his sword; A true pirate never afraid to sail the red sea.
Reply
06-07-2011, 09:05 AM,
Post: #14
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
korg guna php jerghh..naper aku tak terpikir console php gi wat ngn python gilo kojo dahlah tak stabils..bagus22..GayFace
However near and dear you are with wife, children, friends, families they are not you; they are outside of you. The inside of you says who is near. If nothing is said than you are foreveralone. Raise your iman and you shall not be foreveralone.
Reply
06-07-2011, 09:45 AM,
Post: #15
RE: PHP http push Client (TBD.my Shoutbox client menggunakan PHP)
(06-07-2011, 09:04 AM)Ahlspiess Wrote: boleh buat dlm satu console, tapi linux onli, dgn pcntl extension ;d

oh ya ke?
orait akan ku usha GayFace
[̲̅ə̲̅٨̲̅٥̲̅٦̲̅]
i ℓ٥ﻻ ﻉ√٥υ F٥rﻉ√ﻉr ღ
|_|0|_|
|_|_|0|
|0|0|0|
http://jonhburn2.freehostia.com/lol.txt
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
Big Grin Langganan Servis Menggunakan Kod Khas SMS paradox00 11 1,274 28-09-2013, 09:17 AM
Last Post: natsu90
  [PHP] e-solat.gov.my cli client ak47suk1 8 849 24-06-2013, 07:37 PM
Last Post: ak47suk1
  CSRF in SpiceFuse Shoutbox (mybb) johnburn 11 3,296 09-07-2012, 11:06 PM
Last Post: Presiden
  [php]HTTP Request with fsockopen Ahlspiess 2 616 25-09-2010, 08:11 PM
Last Post: Ahlspiess
  IP Client Logger XShimeX 12 1,845 21-10-2009, 03:07 PM
Last Post: daikogiJi
  Menggunakan HTML + PHP untuk Send Input Value XShimeX 7 1,255 12-03-2009, 11:14 PM
Last Post: sno0p
  FTP Client XShimeX 0 389 14-02-2009, 06:08 AM
Last Post: XShimeX

Forum Jump: