Using PHP with WebSocket

Is it possible to use PHP with WebSocket? Let's figure out
16 October 2017   3632

Unfortuantelly, PHP is not designed to work with WebSocket. You can connect it, but your code will be full of while (true) and fsock_open . And you have to have access to the shell to run the WS-server with php-cgi. 

You need to choose a language that supports threads / asynchronous communication. Now on the top is Node.js. In addition, better use dedicated libraries to support older browsers, etc. If you want to create one-to-all communication (eg chat, broadcast messaging), go one step further and use one of the Bayeuximplementations, for example: Faye.

The mod_proxy_wstunnel extension adds an extra layer to the WS server. Depending on the configuration, it can support DDoS, queue, load-balancing, local port swapping, and https support. But better use this for nginx.

Websockets are events, and PHP is poorly managed with it.

PHP 7.4 to be Available

The giant number of features and improvements are included in the newest update
02 December 2019   184

After a year of development, the release of the PHP 7.4 programming language is presented. The new branch includes a series of new features, as well as several changes that violate compatibility.

Key improvements in PHP 7.4:

  • Typed Properties
  • Arrow Functions
  • Limited Return Type Covariance and Argument Type Contravariance
  • Unpacking Inside Arrays
  • Numeric Literal Separator
  • Weak References
  • Allow Exceptions from __toString()
  • Opcache Preloading
  • Several Deprecations
  • Extensions Removed from the Core

The functions get_magic_quotes_gpc (), get_magic_quotes_runtime (), hebrevc (), convert_cyr_string (), money_format (), ezmlm_hash (),restore_include_path (), ldap_control_paged_result_response__preport (), are declared obsolete.

A warning is provided about using an outdated feature when trying to process invalid characters in the base_convert (), bindec (), octdec (), and hexdec () functions, as well as when specifying a non-string pattern in mb_ereg_replace ().

Get more information at the official website.