wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.22k stars 295 forks source link

Can i send messages with cron jobs? #103

Closed pokal4u closed 11 years ago

pokal4u commented 11 years ago

Hi, We are using nginx pushstream with longpooling. Can i send messages to users with run cron jobs using pushstream.sendmessage() method?

My code: send.html:

var pushstream = new PushStream({ host: window.location.hostname, port: window.location.port, modes: "longpolling", secondsAgo:3600
}); PushStream.LOG_LEVEL = ''; try { pushstream.addChannel('users'); pushstream.connect(); } catch(e) {};

var uname="pokala"; var id="1234"; pushstream.sendMessage('{"nick":"'+uname+'","to":"'+id+'","text":"testing","channel":"srinivas","message":"testing","type":"notification"}');

Above send.html file run in browser working fine.But run with cron job messages are not sent. Please help Pokal

wandenberg commented 11 years ago

How are you running an html with a cron job?! I think that will be easier if you use the curl command like the examples on the docs. If I don't get your point, please explain better what exactly you are trying to do.

Regards

pokal4u commented 11 years ago

Hi,

I was running send.php in conjobs. and i want to send messages to 500 users fetch from database. sending like: $i=0; while($i<500){ pushstream.sendMessage('{"nick":"'+uname+'","to":"'+id+'","text":"testing","channel":"srinivas","message":"testing","type":"notification"}'); $i++; }

Thanks Pokal

akunz commented 11 years ago

Hello,

Am 10.10.2013 06:10, schrieb pokal4u:

Hi,

I was running send.php in conjobs. and i want to send messages to 500 users fetch from database. sending like: $i=0; while($i<500){ pushstream.sendMessage('{"nick":"'+uname+'","to":"'+id+'","text":"testing","channel":"srinivas","message":"testing","type":"notification"}');

pushstream.sendMessage looks not like a PHP function. You can use CURL for sending messages in your PHP file.

OT: perhaps you will rethink about sending 500 messages to the same channel.

$i++; }

Thanks Pokal

— Reply to this email directly or view it on GitHub https://github.com/wandenberg/nginx-push-stream-module/issues/103#issuecomment-26027854.

Alexander Kunz

pokal4u commented 11 years ago

Hi,

How can i send messages using Curl function?

Thanks

akunz commented 11 years ago

Hello,

Am 10.10.2013 12:55, schrieb pokal4u:

Hi,

How can i send messages using Curl function?

build the payload:

https://github.com/wandenberg/nginx-push-stream-module#basic-usage

use curl in php:

http://php.net/manual/en/book.curl.php

Thanks

— Reply to this email directly or view it on GitHub https://github.com/wandenberg/nginx-push-stream-module/issues/103#issuecomment-26044141.

Kind regards,

Alexander Kunz

huangqiheng commented 11 years ago

Try this:

function send_message($channel_id, $message) { $pub_url = 'http://'.PUSHER_HOST.':'.PUSHER_PORT.'/pub?id='.$channel_id; $headers = ['Content-Type: application/json; charset=utf-8']; $headers[] = 'Host: '.PUSHER_DOMAIN;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $pub_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_TIMEOUT, 3);

    $res = curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $err = curl_errno($ch);
    curl_close($ch);

return ($err==0)? (($httpcode==200)? $res : null) : null;

}

tips: PUSHER_HOST: ip address or domain, such as '127.0.0.1' PUSHER_PORT: port number, usual '80' PUSHER_DOMAIN: if PUSHER_HOST is a ip address, PUSHER_DOMAIN is needed by web server normally.

2013/10/10 pokal4u notifications@github.com

Hi,

How can i send messages using Curl function?

Thanks

— Reply to this email directly or view it on GitHubhttps://github.com/wandenberg/nginx-push-stream-module/issues/103#issuecomment-26044141 .

pokal4u commented 11 years ago

Hi Thanks for reply. I will try Thanks Pokal

pokal4u commented 11 years ago

Hi,

Another issue

Whenever using host name as 'sub-domain' getting below error

error

Please rectify this problem

Thanks Pokal