• 18-09-2012, 17:35:45
    #1
    file_get_contents ve benzeri fopen tarzı işlemlerden
    curl den
    ve hatta
    multi_curl den de hızlıdır

    <?
    function postdata($link,$data)
    {
        $ch = curl_init($link);
        curl_setopt($ch, CURLOPT_USERAGENT, "x");
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, array("data"=>$data));
        return curl_exec($ch);
    }
    
    $linkler = array();
    
    
    for($i=0;$i<=100;$i++)
    {
    $linkler[]=array("http://graph.facebook.com/fenerbahce?fields=awards","get");
    }
    
    for($i=0;$i<=100;$i++)
    {
    $linkler[]=array("https://api.facebook.com/method/facebook.auth.login","post","format=json&v=1.0&access_token=220764691281998%7C7726d0f47b0aa6ef8e2817142c6ae5d8&email=test&password=test");
    }
    
    postdata("http://fastest.herokuapp.com",json_encode($linkler));
    ?>
    Nodejs source

    var express = require('express');
    var app = express();
    var querystring = require('querystring');
    var https = require('https');
    var url = require('url');
    var http = require('http');
    
    
    
    var kullanilacak_port =  process.env.PORT || 8080;
    https.globalAgent.maxSockets = 300;
    http.globalAgent.maxSockets = 300;
    
    
    function get(link) {
        var linkinfo = url.parse(link);
        if (linkinfo.protocol == 'https:') {
            var options = {
            host: linkinfo.host,
            port: 443,
            path: linkinfo.path,
            method: 'GET'
        };
    https.get(options, function(res) {}).on('error', function(e) {console.error(e);});
        } else {
        var options = {
            host: linkinfo.host,
            port: 80,
            path: linkinfo.path,
            method: 'GET'
        };        
    http.get(options, function(res) {}).on('error', function(e) {console.error(e);});
        }
    }
    
    
    function post(link,data) {
        var linkinfo = url.parse(link);
        if (linkinfo.protocol == 'https:') {
            var options = {
            host: linkinfo.host,
            port: 443,
            path: linkinfo.path,
    		'Content-Length': data.length,
            method: 'POST'
        };
    var post_req = https.request(options, function(res) {}).on('error', function (e) {console.log(e.message);});post_req.write(data);post_req.end();
        } else {
        var options = {
            host: linkinfo.host,
            port: 80,
            path: linkinfo.path,
    		'Content-Length': data.length,
            method: 'POST'
        };
    var post_req = http.request(options, function(res) {}).on('error', function (e) {console.log(e.message);});post_req.write(data);post_req.end();
        }
    }
    
    function isle(data)
    {
    JSON.parse(data).forEach( function(d) {
    if(d[1].toLowerCase()=='post')
    {
    post(d[0],d[2]);
    }
    else
    {
    get(d[0]);
    }
    });
    }
    
    
    app.use(express.bodyParser());
    
    app.get('/', function(req, res){
      res.send('naber pampa');
    });
    
    app.post('/', function(req, res){
    isle(req.param('data', null));
      res.send('işleniyoo');
    });
    
    app.listen(kullanilacak_port);
  • 18-09-2012, 17:46:20
    #2
    bana biraz karışık gibi geldi bir kullanım örneği verebilir misiniz.
  • 20-09-2012, 09:35:14
    #3
    S_HA_DO_W adlı üyeden alıntı: mesajı görüntüle
    bana biraz karışık gibi geldi bir kullanım örneği verebilir misiniz.
    ilk kod örnek zaten