Logo
  • PHP
    • HipHop / HHVM
    • Modern PHP
    • PHPStorm
    • LAMP
    • Laravel
    • Composer
    • PDO
  • JavaScript
    • node.js
    • AngularJS
  • CSS
    • SASS
    • “CSS4” (CSS level 4)
  • HTML
  • Git
  • LAMP
  • Vagrant
  • UI / UX
  • Architecture of …
  • Off-Topic
With ♥ from Berlin
November 19, 2013
Chris
JavaScript, PHP
0

New GitHub repo: simple php-long-polling for creating real-time apps

PreviousNext
php

Mornin’ !

I’ve just pushed a sweet little new project into GitHub: A very simple and totally reduced PHP long-polling demo application, called php-long-polling. No installation, just copy, edit and run (you need Apache/PHP running).

Long-polling makes near “real-time” applications possible. So, this means that whenever “data” is updated on the server, the client will INSTANTLY be updated. For the end-user it feels like “real-time”.

The technique behind this is really simple: Usually, in an “always very up-to-date” application the client ask the server for new data in intervals, let’s say once per minute. This might work, but bombs the server with requests. Just imagine you have 10.000 people on your site, everyone sending requests permanently, once per minute. That’s (averaged) 167 per second.

With long-polling, the client sends a request – and gets no direct answer. The client-server connection is kept open, the request still pending. This can take hours. When the server has “new data” suddenly, the requested script (might be a simple .php) delivers the data, the client gets the data, the connection is closed… and the whole thing starts again until there’s new data.

This offers excellent possibilities for near real-time application or passive monitoring. For basic apps, we don’t even need special tools, a simple .html, simple js. and a simple .php is everything you need.

 

The right webserver

Biggest issue! When having a lot of connection to clients open, the Apache server will create a thread (?) for every request – which results in a quite large usage of RAM. As the casual apache thread is 15 MB, this might sum up dramatically quite fast. There’s a lot of opposing opinions on that on the web, I’m still not sure what to use, some people say NGINX and lighttpd are perfect, some say node.js is the only way to go – but that’s a totally different topic. Appserver.io also seems promising.

Has anyone here experiences in scaling long-polled js/php applications ? What’s the way to go when it comes to servers ? Feel free to comment…

 

This article was written quite a while ago (9 years), please keep this in mind when using the information written here. Links, code and commands might be outdated or broken.

Random articles

  • Learn AngularJS in 20 (or 90) minutes with Dan WahlinLearn AngularJS in 20 (or 90) minutes with Dan Wahlin
  •  Netflix JavaScript Talks about ECMAScript 7: The Evolution of JavaScript Netflix JavaScript Talks about ECMAScript 7: The Evolution of JavaScript
  • The New Era of JavaScript (28min conference talk, Jack Franklin, 2013)The New Era of JavaScript (28min conference talk, Jack Franklin, 2013)
  • JavaScript Testing Tactics (21min video by Justin Searls)JavaScript Testing Tactics (21min video by Justin Searls)
  • How JavaScript really works – An introduction into the JavaScript call stack by Philip Roberts (20min video)How JavaScript really works – An introduction into the JavaScript call stack by Philip Roberts (20min video)
  • O’Reilly’s Learning JavaScript Design Patterns by Addy Osmani for freeO’Reilly’s Learning JavaScript Design Patterns by Addy Osmani for free
  • O’Reilly’s Programming JavaScript Applications  by Eric Elliott for free (Early Access release)O’Reilly’s Programming JavaScript Applications by Eric Elliott for free (Early Access release)
  • [german] Modernes Frontend-Development mit Bower, Grunt, Yeoman (45min Video, Thorsten Rinne auf der IPC2013)[german] Modernes Frontend-Development mit Bower, Grunt, Yeoman (45min Video, Thorsten Rinne auf der IPC2013)
  • How blind people use websites (video with Sina Bahram, blind accessibility researcher)How blind people use websites (video with Sina Bahram, blind accessibility researcher)
ajaxJavaScriptjqueryJSlong-pollingPHPreal-time
Share this

Leave A Comment Cancel reply

Test GZIP compression of your server easily

If you are running servers (which you hopefully do), then Gzip compression should be a topic, as this simple thing

Quick fix for 404 error in WordPress category / tag page

Just a quick fix for a common problem: Sometimes, especially after switching themes, wordpress will generate 404 errors on the

shadow dom

Crossbrowser-safe HTML5 video (IE6+) with a few lines of code and just one .mp4 video file

No time to read the full article ? Get the code directly here on GitHub: panique/html5-video. Publishing a video on

php uk conference

Slides & talks from PHP UK Conference 2014

The slides of most of PHP UK CONFERENCE 2014‘s talks are online, very interesting stuff, have a look. And a

php

How to install sqlite driver for PHP in Ubuntu & Debian

It’s easy to install sqlite (for usage with PHP): sudo apt-get install php5-sqlite This will also restart apache (on modern

Serious hard-to-fix bug in OAuth and OpenID discovered, lots of major sites affected

Just a short notice rather than a real article, full story later (I need to check the facts): Several sources

mod-rewrite-ubuntu-14-04-lts

How to install / setup PHP 5.5.x on Ubuntu 12.04 LTS

Please note: This works fine. But this package will also upgrade your apache to version 2.4 which has different config

JavaScript ECMAScript6 – A short video introduction (5min)

Excellent introduction into the new ECMAScript6, the spec behind JavaScript. This article was written quite a while ago (7 years),

hiphop php

HipHop VM reaches 100% green Unit Tests in Laravel, Drupal, Slim, CodeIgniter etc.

In September 2013 the PHP HipHop VM dev team wrote a very interesting article [1] about failing Unit Tests of

php

How the PHP session garbage collector really works

Sessions in PHP are easy to handle, but have a tricky configuration underneath. The common opinion is, that when you

1/4

Categories

Search

Ghost
[FREE SERVER PROMO] Install GHOST for free on a free SSD server with this coupon
the-php-login-project
How to install php-login-one-file on Ubuntu 12.04 LTS
Migrating Wikipedia to HHVM (@Scale Conference 2014)
Dangerous Performance Myths in the Web (video talk by Thomas Lohner, PHPUG Latvia)
the-php-login-project
How to install php-login-minimal on Ubuntu 12.04 LTS
What’s new in PHPStorm 9
Hacking ATMs – A conference talk about the current security state of Windows XP driven cash machines
windows-xp-eol
Windows XP is officially dead from today. Do you know people still using it ? Punch them.
mod-rewrite-ubuntu-14-04-lts
How to enable mod_rewrite in Ubuntu 14.04 LTS
twig
A 6min video introduction into Twig, the PHP templating engine
vagrant
How to setup a local server (in a virtual machine) with Vagrant in PHPStorm
DEF CON 18 – When your computer got stolen and you can still SSH into it: “Pwned by the 0wner” (22min conference talk)
php
PHP.net hacked, but most things are fine again
GitHub introduces revert button / rollback for merged pull requests
Frontend Ops Conf 2014 – Rebooting Flickr On A Node.js Stack, One Page At A Time (from PHP) by Bertrand Fan

Tags

apache bash centos composer conference coupon CSS debian fonts framework git GitHub hack HHVM HipHop HTML HTML5 IDE JavaScript JS LAMP laravel linux mod_rewrite MVC MySQL Nginx optimization PHP PHP 5.5 PHP 5.6 phpmyadmin PHPStorm security server SSD Ubuntu UI UX vagrant video virtual machine voucher VPS wordpress
Side-Project: Wordle-Solver:
www.wordle-helper.info

Pages

  • Privacy Policy
 
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT