Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Processing

Christian Mayer edited this page Nov 3, 2014 · 20 revisions

PHPChat consists in the form of the following processes:

  • Kernel
  • Cronjob
  • Console
  • IMAP
  • SMTP

Kernel

The kernel is the core of PHPChat. Every single other process is communicating over an IPC-layer with the kernel. The kernel is design for responding quickly. It shouldn't do any long processing cycles because it's responsible for saving files and holding the whole PHPChat system up-to-date. Also the objects for the main data files (such as Settings) are managed by this process. It manages the server and all connected clients.

You can run the kernel process in daemon mode:

./application.php kernel -d

Kernel Objects

Kernel -> Server -> Client(s)

The kernel only has one Server. The server is proper for listening for incoming connections and clients handling. It also creates new clients for outgoing connections. Other processes doesn't communicate directly with the server or client(s) but through the kernel.

For example if the Cronjob process would like to create a new outgoing connection to a node it communicates with the kernel. The kernel then calls a server function which creates a new client and handles this client.

Problem: in the current version of PHPChat the Client class (which is executed by the Kernel process) mines new Hashcash. This reduces the reactivity of the kernel. In the future only the Cronjob should take over this feature. Beside the received Hashcash the Hashcash DB must also include new minted Hashcash for paying.

Cronjob

Beside the kernel process the cronjob is the second important process needed for the PHPChat system. The mission of the cronjob process is to push the kernel to take action. It initializes the kernel to ping close nodes, save data files, relay messages and enclose unknown nodes in regular intervals. It's like a second kernel but for less important jobs. It SHOULD take care about long-term processing functions.

You can run the cronjob process in daemon mode:

./application.php cronjob -d

It's also possible to let the cronjob only run one cycle:

./application.php cronjob -c

Use the -c command also to include the process to a time-based job scheduler (like Cron) of the operating system:

*/3 * * * * /path/to/application.php cronjob -c &> /dev/null

Every 3 minutes is recommended.

Console

Start the console:

./application.php console

Type /help to list all available commands in the console. All commands begin with a slash (/).

IMAP

Optional. Run this only if you want do send messages through a MUA.

Project page: https://github.com/TheFox/imapd

You can run the imap process in daemon mode:

./application.php imap -d

SMTP

Optional. Run this only if you want do send messages through a MUA.

Project page: https://github.com/TheFox/smtpd

You can run the smtp process in daemon mode:

./application.php smtp -d

Info

Run the info command to show some informations about the local node.

./application.php info

To show live statistics about the connections run the info command in combination with -c:

./application.php info -c

IPC

IPC stands for Inter-Process Communication. The IPC layer is a set of PHP objects in the TheFox\Ipc namespace. The basic layer of the IPC module are BSD sockets. IPC enables prallel processing.

Why not using pthreads? I tried pthreads in the every first version of PHPChat but it sucked again and again and again. So after 2 months of coding PHPChat with pthreads I decided to not contaminate my project with pthreads. Just don't use it. At some point you can't continue coding with pthreads. So I killed pthreads from PHPChat and re-coded everything with my own version of a IPC layer.

Components Diagram

Clone this wiki locally