Rectangle 27 1

Using comet with PHP?


+1 because Apache/PHP are not good options for scaling out a comet solution. Options for PHP users are 1) as you mentioned, crazy configurations of additional servers and proxies or 2) using a SaaS solution and offloading the comet stuff via something like WebSync On-Demand.

@MikeHouston What about trying comet with php in IIS.?

@ravz, there's some stuff here about IIS and comet: stackoverflow.com/questions/1898848/comet-programming-in-iis, but I suspect the fast-cgi PHP module has the same limitations as with apache. It mentions a single threaded environment here: microsoft.com/web/platform/phponwindows.aspx - I don't use Windows servers myself, so I'm not sure about the threading model.

Agreeing/expanding what has already been said, I don't think FastCGI will solve the problem.

Each request into Apache will use one worker thread until the request completes, which may be a long time for COMET requests.

Now, considering the other side of the problem, even if you resolve the issue with holding up one thread per comet request, you will still need one PHP thread per request - this is why FastCGI won't help.

The suggested solution was to use the 'event' MPM module which changes the way requests are dispatched to worker threads.

There's an article here about using a load balancer (HAProxy) to allow you to run both an apache server and a comet-enabled server (e.g. jetty, tomcat for Java) on port 80 of the same server.

This MPM tries to fix the 'keep alive problem' in HTTP. After a client completes the first request, the client can keep the connection open, and send further requests using the same socket. This can save signifigant overhead in creating TCP connections. However, Apache traditionally keeps an entire child process/thread waiting for data from the client, which brings its own disadvantages. To solve this problem, this MPM uses a dedicated thread to handle both the Listening sockets, and all sockets that are in a Keep Alive state.

This article on Ajaxian mentions using COMET on Apache, and that it is difficult. The problem isn't specific to PHP, and applies to any back-end CGI module you may want to use on Apache.

This is wrong in several aspects. If one wants to leave the one-thread-per-user method, it can be easily achieved by removing Apache as an intermediary and let PHP handle these requests. Of course, Apache works better at serving content, so I would run this apache-less PHP sever on a subdomain that does not serve any content.

Unfortunately, that doesn't work either, because it will only 'snooze' after a request is complete, waiting for a new request from the client.

You need something like Continuations which allow the comet requests to be resumed when the event they are triggered by is observed. AFAIK, this isn't something that's possible in PHP. I've only seen it in Java - see the Apache Tomcat server.

Note
Rectangle 27 1

Using comet with PHP?


+1 because Apache/PHP are not good options for scaling out a comet solution. Options for PHP users are 1) as you mentioned, crazy configurations of additional servers and proxies or 2) using a SaaS solution and offloading the comet stuff via something like WebSync On-Demand.

@MikeHouston What about trying comet with php in IIS.?

@ravz, there's some stuff here about IIS and comet: stackoverflow.com/questions/1898848/comet-programming-in-iis, but I suspect the fast-cgi PHP module has the same limitations as with apache. It mentions a single threaded environment here: microsoft.com/web/platform/phponwindows.aspx - I don't use Windows servers myself, so I'm not sure about the threading model.

Agreeing/expanding what has already been said, I don't think FastCGI will solve the problem.

Each request into Apache will use one worker thread until the request completes, which may be a long time for COMET requests.

Now, considering the other side of the problem, even if you resolve the issue with holding up one thread per comet request, you will still need one PHP thread per request - this is why FastCGI won't help.

The suggested solution was to use the 'event' MPM module which changes the way requests are dispatched to worker threads.

There's an article here about using a load balancer (HAProxy) to allow you to run both an apache server and a comet-enabled server (e.g. jetty, tomcat for Java) on port 80 of the same server.

This MPM tries to fix the 'keep alive problem' in HTTP. After a client completes the first request, the client can keep the connection open, and send further requests using the same socket. This can save signifigant overhead in creating TCP connections. However, Apache traditionally keeps an entire child process/thread waiting for data from the client, which brings its own disadvantages. To solve this problem, this MPM uses a dedicated thread to handle both the Listening sockets, and all sockets that are in a Keep Alive state.

This article on Ajaxian mentions using COMET on Apache, and that it is difficult. The problem isn't specific to PHP, and applies to any back-end CGI module you may want to use on Apache.

This is wrong in several aspects. If one wants to leave the one-thread-per-user method, it can be easily achieved by removing Apache as an intermediary and let PHP handle these requests. Of course, Apache works better at serving content, so I would run this apache-less PHP sever on a subdomain that does not serve any content.

Unfortunately, that doesn't work either, because it will only 'snooze' after a request is complete, waiting for a new request from the client.

You need something like Continuations which allow the comet requests to be resumed when the event they are triggered by is observed. AFAIK, this isn't something that's possible in PHP. I've only seen it in Java - see the Apache Tomcat server.

Note
Rectangle 27 1

Using comet with PHP?


+1 because Apache/PHP are not good options for scaling out a comet solution. Options for PHP users are 1) as you mentioned, crazy configurations of additional servers and proxies or 2) using a SaaS solution and offloading the comet stuff via something like WebSync On-Demand.

@MikeHouston What about trying comet with php in IIS.?

@ravz, there's some stuff here about IIS and comet: stackoverflow.com/questions/1898848/comet-programming-in-iis, but I suspect the fast-cgi PHP module has the same limitations as with apache. It mentions a single threaded environment here: microsoft.com/web/platform/phponwindows.aspx - I don't use Windows servers myself, so I'm not sure about the threading model.

Agreeing/expanding what has already been said, I don't think FastCGI will solve the problem.

Each request into Apache will use one worker thread until the request completes, which may be a long time for COMET requests.

Now, considering the other side of the problem, even if you resolve the issue with holding up one thread per comet request, you will still need one PHP thread per request - this is why FastCGI won't help.

The suggested solution was to use the 'event' MPM module which changes the way requests are dispatched to worker threads.

There's an article here about using a load balancer (HAProxy) to allow you to run both an apache server and a comet-enabled server (e.g. jetty, tomcat for Java) on port 80 of the same server.

This MPM tries to fix the 'keep alive problem' in HTTP. After a client completes the first request, the client can keep the connection open, and send further requests using the same socket. This can save signifigant overhead in creating TCP connections. However, Apache traditionally keeps an entire child process/thread waiting for data from the client, which brings its own disadvantages. To solve this problem, this MPM uses a dedicated thread to handle both the Listening sockets, and all sockets that are in a Keep Alive state.

This article on Ajaxian mentions using COMET on Apache, and that it is difficult. The problem isn't specific to PHP, and applies to any back-end CGI module you may want to use on Apache.

This is wrong in several aspects. If one wants to leave the one-thread-per-user method, it can be easily achieved by removing Apache as an intermediary and let PHP handle these requests. Of course, Apache works better at serving content, so I would run this apache-less PHP sever on a subdomain that does not serve any content.

Unfortunately, that doesn't work either, because it will only 'snooze' after a request is complete, waiting for a new request from the client.

You need something like Continuations which allow the comet requests to be resumed when the event they are triggered by is observed. AFAIK, this isn't something that's possible in PHP. I've only seen it in Java - see the Apache Tomcat server.

Note
Rectangle 27 1

Using comet with PHP?


  • It uses file I/O which is much slower then just getting data from memory. Like for example the functions filemtime(),
  • Second, but I don't think least PHP does not a have a decent thread model. PHP was not designed for this anyway because of the share nothing model. Like the slides says "Shared data is pushed down to the data-store layer" like for example MySQL.

I found this funny little screencasts explaining simple comet. As a side note I really think this is going to kill your server on any real load. When just having a couple of users, I would say to just go for this solution. This solution is really simple to implement(screencasts only takes 5 minutes of your time :)). But as I was telling previously I don't think it is good for a lot of concurrent users(Guess you should benchmark it ;)) because:

I really think you should try the alternatives if you want to do any comet/long polling. You could use many languages like for example:

Just performing a simple google search, will show you a lot alternatives also PHP(which I think on any big load will kill your server).

Note
Rectangle 27 1

Using comet with PHP?


  • It uses file I/O which is much slower then just getting data from memory. Like for example the functions filemtime(),
  • Second, but I don't think least PHP does not a have a decent thread model. PHP was not designed for this anyway because of the share nothing model. Like the slides says "Shared data is pushed down to the data-store layer" like for example MySQL.

I found this funny little screencasts explaining simple comet. As a side note I really think this is going to kill your server on any real load. When just having a couple of users, I would say to just go for this solution. This solution is really simple to implement(screencasts only takes 5 minutes of your time :)). But as I was telling previously I don't think it is good for a lot of concurrent users(Guess you should benchmark it ;)) because:

I really think you should try the alternatives if you want to do any comet/long polling. You could use many languages like for example:

Just performing a simple google search, will show you a lot alternatives also PHP(which I think on any big load will kill your server).

Note
Rectangle 27 1

Using comet with PHP?


  • It uses file I/O which is much slower then just getting data from memory. Like for example the functions filemtime(),
  • Second, but I don't think least PHP does not a have a decent thread model. PHP was not designed for this anyway because of the share nothing model. Like the slides says "Shared data is pushed down to the data-store layer" like for example MySQL.

I found this funny little screencasts explaining simple comet. As a side note I really think this is going to kill your server on any real load. When just having a couple of users, I would say to just go for this solution. This solution is really simple to implement(screencasts only takes 5 minutes of your time :)). But as I was telling previously I don't think it is good for a lot of concurrent users(Guess you should benchmark it ;)) because:

I really think you should try the alternatives if you want to do any comet/long polling. You could use many languages like for example:

Just performing a simple google search, will show you a lot alternatives also PHP(which I think on any big load will kill your server).

Note
Rectangle 27 1

Using comet with PHP?


+1 because Apache/PHP are not good options for scaling out a comet solution. Options for PHP users are 1) as you mentioned, crazy configurations of additional servers and proxies or 2) using a SaaS solution and offloading the comet stuff via something like WebSync On-Demand.

@MikeHouston What about trying comet with php in IIS.?

@ravz, there's some stuff here about IIS and comet: stackoverflow.com/questions/1898848/comet-programming-in-iis, but I suspect the fast-cgi PHP module has the same limitations as with apache. It mentions a single threaded environment here: microsoft.com/web/platform/phponwindows.aspx - I don't use Windows servers myself, so I'm not sure about the threading model.

Agreeing/expanding what has already been said, I don't think FastCGI will solve the problem.

Each request into Apache will use one worker thread until the request completes, which may be a long time for COMET requests.

Now, considering the other side of the problem, even if you resolve the issue with holding up one thread per comet request, you will still need one PHP thread per request - this is why FastCGI won't help.

The suggested solution was to use the 'event' MPM module which changes the way requests are dispatched to worker threads.

There's an article here about using a load balancer (HAProxy) to allow you to run both an apache server and a comet-enabled server (e.g. jetty, tomcat for Java) on port 80 of the same server.

This MPM tries to fix the 'keep alive problem' in HTTP. After a client completes the first request, the client can keep the connection open, and send further requests using the same socket. This can save signifigant overhead in creating TCP connections. However, Apache traditionally keeps an entire child process/thread waiting for data from the client, which brings its own disadvantages. To solve this problem, this MPM uses a dedicated thread to handle both the Listening sockets, and all sockets that are in a Keep Alive state.

This article on Ajaxian mentions using COMET on Apache, and that it is difficult. The problem isn't specific to PHP, and applies to any back-end CGI module you may want to use on Apache.

This is wrong in several aspects. If one wants to leave the one-thread-per-user method, it can be easily achieved by removing Apache as an intermediary and let PHP handle these requests. Of course, Apache works better at serving content, so I would run this apache-less PHP sever on a subdomain that does not serve any content.

Unfortunately, that doesn't work either, because it will only 'snooze' after a request is complete, waiting for a new request from the client.

You need something like Continuations which allow the comet requests to be resumed when the event they are triggered by is observed. AFAIK, this isn't something that's possible in PHP. I've only seen it in Java - see the Apache Tomcat server.

Note
Rectangle 27 1

Using comet with PHP?


  • It uses file I/O which is much slower then just getting data from memory. Like for example the functions filemtime(),
  • Second, but I don't think least PHP does not a have a decent thread model. PHP was not designed for this anyway because of the share nothing model. Like the slides says "Shared data is pushed down to the data-store layer" like for example MySQL.

I found this funny little screencasts explaining simple comet. As a side note I really think this is going to kill your server on any real load. When just having a couple of users, I would say to just go for this solution. This solution is really simple to implement(screencasts only takes 5 minutes of your time :)). But as I was telling previously I don't think it is good for a lot of concurrent users(Guess you should benchmark it ;)) because:

I really think you should try the alternatives if you want to do any comet/long polling. You could use many languages like for example:

Just performing a simple google search, will show you a lot alternatives also PHP(which I think on any big load will kill your server).

Note
Rectangle 27 1

Using comet with PHP?


A new module just came out for the nginx web server that'll allow Comet with any language, including PHP.

Note
Rectangle 27 1

Using comet with PHP?


<?php

$i = 0;

$app = function ($request, $response) use (&$i) {
    $i++;

    $text = "This is request number $i.\n";
    $headers = array('Content-Type' => 'text/plain');

    $response->writeHead(200, $headers);
    $response->end($text);
};

$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);

$http->on('request', $app);

$socket->listen(1337);
$loop->run();

React is a low-level library for event-driven programming in PHP. At its core is an event loop, on top of which it provides low-level utilities, such as: Streams abstraction, async dns resolver, network client/server, http client/server, interaction with processes. Third-party libraries can use these components to create async network clients/servers and more.

The event loop is based on the reactor pattern (hence the name) and strongly inspired by libraries such as EventMachine (Ruby), Twisted (Python) and Node.js (V8).

The introductory example shows a simple HTTP server listening on port 1337:

Note