Programming/node.js2014. 9. 18. 19:14

1. http/ querystring만 사용


  1. var http = require('http')
  2. ,qs = require('querystring');
  3. http.createServer(function (req, res) {
  4. if( req.url == '/' && req.method == 'POST'){
  5. var postBody = '';
  6. req.on('data', function (data) {
  7. postBody += data;
  8. });
  9. req.on('end', function () {
  10. var post = qs.parse(postBody);
  11. //post데이터확인
  12. console.log(post['postname']);
  13. });
  14. res.end('true');
  15. }else{
  16. res.writeHead(404, {'Content-Type': 'text/plain'});
  17. res.end('404 ERROR');
  18. }
  19. }).listen(8001);


2. http / express  / body-parser 사용


  1. var express = require('express')
  2. ,http = require('http')
  3. ,bodyParser = require('body-parser');
  4. var app = express();
  5. app.use(bodyParser.urlencoded({extended: true}));
  6. //app.use(bodyParser.json());
  7. app.post("/", function( req, res){
  8. res.writeHead(200,{"Content-Type" : "text/plain"});
  9. //post데이터확인
  10. console.log(req.param('postname',null));
  11. res.end('test');
  12. });
  13. app.use(function( req, res){
  14. res.writeHead(404,{"Content-Type" : "text/plain"});
  15. res.end('404 ERROR');
  16. });
  17. http.createServer(app).listen(8001);


Posted by 시니^^
Programming/PHP2014. 9. 18. 16:16



elephant.io https://github.com/Wisembly/elephant.io


1. elephantio.php -  elephant.io 다운로드 src폴더 데이터에 대한 include 또는 require 파일 만들기

  1. <?php
  2. $___ELEPHANTIO_DIR = dirname(__FILE__);
  3. require $___ELEPHANTIO_DIR.'/Client.php';
  4. require $___ELEPHANTIO_DIR.'/AbstractPayload.php';
  5. require $___ELEPHANTIO_DIR.'/EngineInterface.php';
  6. require $___ELEPHANTIO_DIR.'/Engine/AbstractSocketIO.php';
  7. require $___ELEPHANTIO_DIR.'/Engine/SocketIO/Session.php';
  8. require $___ELEPHANTIO_DIR.'/Engine/SocketIO/Version1X.php';
  9. require $___ELEPHANTIO_DIR.'/Exception/MalformedUrlException.php';
  10. require $___ELEPHANTIO_DIR.'/Exception/ServerConnectionFailureException.php';
  11. require $___ELEPHANTIO_DIR.'/Exception/SocketException.php';
  12. require $___ELEPHANTIO_DIR.'/Exception/UnsupportedActionException.php';
  13. require $___ELEPHANTIO_DIR.'/Exception/UnsupportedTransportException.php';
  14. require $___ELEPHANTIO_DIR.'/Payload/Decoder.php';
  15. require $___ELEPHANTIO_DIR.'/Payload/Encoder.php';
  16. ?>


2. client.php

  1. <?php
  2. include 'lib/elephantio/elephantio.php';
  3. /*
  4. * Version1X arg2 Option : ['context'=>[], 'debug'=>false,'wait'=>100*1000,'timeout'=>ini_get("default_socket_timeout")];
  5. */
  6. $EIO = new ElephantIO\Client(
  7. new ElephantIO\Engine\SocketIO\Version1X('http://127.0.0.1:8001',['timeout'=>5])
  8. );
  9. $EIO->initialize();
  10. $EIO->emit('msgIn', array('data1','data2') );
  11. $EIO->close();
  12. ?>


3. nodejs server

  1. var io = require('socket.io').listen(8001);
  2. io.sockets.on('connection', function (socket){
  3. socket.on('msgIn',function(msg){
  4. console.log('Msg In : ',msg);
  5. });
  6. socket.on('disconnect', function(){
  7. console.log('NOT USER DISCONNECT : ', socket.id);
  8. });
  9. });
  10. /*
  11. * debug
  12. * Msg In : [ 'data1', 'data2' ]
  13. * NOT USER DISCONNECT : NPmXDQpuVM9OFYl0AAAA
  14. */


Posted by 시니^^
Programming/PHP2014. 9. 18. 14:49

Github 주소

https://github.com/msgpack/msgpack-php


소스설치방법

$ wget https://github.com/msgpack/msgpack-php/zipball/master -O msgpack-php.zip
$ unzip msgpack-php.zip 
$ cd msgpack-msgpack-php-da24be3/
$ phpize
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212

$ ./configure
$ make && make install
Installing shared extensions:     /usr/lib64/php/modules/
Installing header files:          /usr/include/php/


$ cd /usr/lib64/php/modules/
$ ll | grep msgpack
-rwxr-xr-x 1 root root  388516 Sep 18 14:27 msgpack.so


##### php.conf 디렉토리에 맞게 ini 에 extension 등록하기! 안되면 php.ini등록해도됨
$ echo extension=msgpack.so > /etc/php.d/msgpack.ini 

##### 웹서버종류에 따라서 Apache Restart 또는 php-fpm restart
$ /etc/init.d/php-fpm restart

##### 최종확인
$ php -i | grep 'MessagePack Support'
MessagePack Support => enabled

<?php phpinfo() ?> 
MessagePack Support enabled
Session Support enabled
extension Version   0.5.6-dev
header Version  0.5.4
Directive   Local Value Master Value
msgpack.error_display   On  On
msgpack.illegal_key_insert  Off Off
msgpack.php_only    On  On


Posted by 시니^^