This repository was archived by the owner on Oct 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Improve the socket layer #12
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
The socket layer was written with little knowledge about socket management, it would highly benefit from a rewrite. First, those issues must be fixed:
- Payloads sent through sockets are manually splitted in multiple chunks. This was done because the
socket_read()method requires to specify the maximum number of bytes to read. For an unknown reason, I chose to implement a system based on chunks instead of callingsocket_read()multiple times (until it returns an empty string). - The payload is encoded in base64 before being sent through the socket, and is decoded right after. This was a naive solution to handle non-ascii characters in the payloads and shouldn't be left as is because it can increase the size of the payload (depending on the data stored in it).
- When multiple chunks are being received, a delay is applied before reading the next chunk. This was added because, on slow environments, the PHP process could try to read the socket stream before the Node process has time to send the next chunk.
Also, the following features could be added for extra security:
- In PHP, we could use streams to store the data retrieved from the socket (to avoid exhausted memory in case of heavy payloads, like base64 images). However, it might not be useful since decoding the JSON payload doesn't handle streams, unless we use a package for this (and this might not be a good idea).
- Check the integrity of the payload by using a cyclic redundancy check (use the hash functions in PHP in PHP, and the crc package for Node).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request