| Last Updated |   | Ratings |   | Unique User Downloads |   | Download Rankings | 
2024-05-22 (10 months ago)   |  | Not enough user ratings |  | Total: 15  |  | All time:  11,435 This week: 64  | 
 | 
| Description |   | Author  | 
This package can exchange chat messages using server-sent events. 
 
It implements a chat system that receives messages from chat users. 
 
The messages are stored in a database and are sent to other chat users using server-sent events. 
 
The package uses a Web server written in Python that supports server-sent events. Innovation Award 
  May 2024 
Number 2 | 
Server-sent events are messages that a Web server can send to browsers connected to the server when relevant events happen on the server side. 
 
This package implements a chat system that uses server-sent events to distribute messages to multiple users who participate in chat rooms. 
 
Manuel Lemos | 
 
 
 
 |  | 
  | 
 | 
Innovation award
   Nominee: 23x
  Winner: 4x |  
 
 
  | 
Example
<?php 
 
require 'vendor/autoload.php'; 
use Chat\App\Chat; 
 
header('Content-Type: application/json'); 
 
if ($_SERVER['REQUEST_METHOD'] === 'POST') { 
    $data = json_decode(file_get_contents('php://input'), true); 
    $message = $data['message'] ?? '';  
    $user = $data['usuario'] ?? '';  
    $chat = new Chat(); 
    $success = $chat->sendMessage($message,$user); 
 
    if ($success) { 
        echo json_encode(['status' => 'success', 'message' => 'Mensagem enviada com sucesso.']); 
    } else { 
        http_response_code(500); 
        echo json_encode(['status' => 'error', 'message' => 'Falha ao enviar a mensagem.']); 
    } 
} else { 
    http_response_code(405); 
    echo json_encode(['status' => 'error', 'message' => 'Método de solicitação não permitido.']); 
} 
 
 
 | 
 
Details
Chat em Tempo Real com PHP e FastAPI
Este projeto implementa um sistema de chat em tempo real utilizando PHP e FastAPI. Ele inclui a integração do padrão Observer com Server-Sent Events (SSE) para notificação em tempo real e permite a interação com um banco de dados compartilhado entre as duas tecnologias.
Tecnologias Utilizadas
composer install
Configuração do Banco de Dados
Crie o banco de dados e a tabela de mensagens:
CREATE TABLE `messages` (
  `id` int NOT NULL AUTO_INCREMENT,
  `message` text NOT NULL,
  `usuario` varchar(50) NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
)
executar o servidor python
na pasta do projeto
pip install -r requeriments.txt
python main.py
<img src="chat.PNG">
 
 
|   | 
Applications that use this package | 
  | 
No pages of applications that use this class were specified.
 If you know an application of this package, send a message to the author to add a link here.