Discussion:
How to implement long-polling using curl-command-line?
AC Pan
2014-10-27 10:52:06 UTC
Permalink
Thanks for your time reading this. I had searched the forum but can't seems
to find a way to do this. I also searched extensively in the internet
trying to implement using other approaches but did not get it work or too
difficult for my level using .


I am trying to implement push notification from a web server using
long-polling like https://github.com/panique/php-long-polling, except that
the client is originated from curl.exe NOT a web browser.



Ideally using long-polling approach, the curl.exe client should be able to
send a HTTP GET/Post to the Server, STAY CONNECTED for the session until
there is new data from the server.



When new data is available, the server return with 1 and some other data
from a database, and the connection is closed and the curl client write the
data to a file or trigger an external program on the PC.


This way, it will reduce the load and traffic without fixed interval
polling from the client.


Questions:


1. Can curl connect to a php server and have the connection stay with the
server until data arrive? How to do it ? i tested Curl.exe, the connection
does not stay. May be i am not aware of syntax used.

2. If not possible to implement above, how about running an external
program that act as a long polling desktop client? what desktop client can
be use?



Many thanks again if you guys can offer any advice.


Best Regards,
AC Pan
Daniel Stenberg
2014-10-27 12:34:21 UTC
Permalink
Post by AC Pan
1. Can curl connect to a php server and have the connection stay with the
server until data arrive? How to do it ? i tested Curl.exe, the connection
does not stay. May be i am not aware of syntax used.
curl will do it by default, nothing extra needed. "long-polling" is just
another word for saying "very very very slow server" and that's of course
something curl supports. Just make sure the server keeps the connection alive.
And you probably want to enable TCP keep-alive for the cases you go through
NATs or firewalls etc.
--
/ daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.ha
AC Pan
2014-10-27 18:51:33 UTC
Permalink
Hi Daniel,

Many thanks for your quick response.

I think you are absolutely right, TCP keep-alive is a good pointer from
you, I will find some time to test again.

Cheers
AC Pan
Post by AC Pan
1. Can curl connect to a php server and have the connection stay with the
Post by AC Pan
server until data arrive? How to do it ? i tested Curl.exe, the connection
does not stay. May be i am not aware of syntax used.
curl will do it by default, nothing extra needed. "long-polling" is just
another word for saying "very very very slow server" and that's of course
something curl supports. Just make sure the server keeps the connection
alive. And you probably want to enable TCP keep-alive for the cases you go
through NATs or firewalls etc.
--
/ daniel.haxx.se
Loading...