PHP + Delphi (Pascal), issue real-time warnings

12

I would like to create a small, simple system, encoded in the Pascal language (IDE delphi), to receive notifications (such as a warning that some event occurred), when the warning sounds.

I understand little of Delphi, it was one of the languages that I started out of curiosity but I ended up dropping it after I came to the WEB platform.

I do not know if it's possible, create something with PHP + Delphi, something like send an email, the software will capture and issue some alert (like a sound) to the client.

I would like this delphi connection to be possible with PHP, but I do not know if it is possible to interact a web platform language with one that is not directly.

    
asked by anonymous 19.10.2015 / 00:16

3 answers

9

I suggest the following architecture: - WebService PHP on the server; - Desktop application, Delphi, querying the WS from the server.

For the desktop application, it does not have much secrecy, use the Timer, and make the application stay in Windows Tray, you can use this component: QTrayIcon .

For calls to the server, you can use the Indy library. / p>

On the server, in PHP it is simple for you to do a simple WebService that reads the call via GET and returns whether changes have been made or not, you can return with a JSON containing the answers you want, something like this:

.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?pg=$1

Simple WS example:

<?php
header("Access-Control-Allow-Origin: *");

$dadosRecebidos = $_GET['pg']);

switch ($_SERVER['REQUEST_METHOD']) {
    case 'GET':
        if ($dadosRecebidos[0] == TESTE){
            echo json_encode(array(MSG_OK, "CONEXAO OK"));
    case ...
...

I also suggest migrating from Delphi to Lazarus , all open -source !

    
28.10.2015 / 12:49
5

Another way to implement this feature, which nobody commented on, is through the use of Webhooks .

The use of "polling", ie checking the server from time to time (via http query or even through direct access to the database) is inefficient in some cases.

If the structure that your friend Alexandre presented allows the web application to connect to the client terminal, you can create an application in Delphi that is a mini web server that will wait for connections. When this web server receives some connection, it can even display the message in some way to the user (in the notifications area, for example).

The advantage of webhooks is that the notification will happen in real time, that is, at the very moment the event occurs in the web application.

An interesting framework that can make this feature easy to implement is the Brook Framework .

    
29.10.2015 / 14:16
4

Currently I use this on a system inside where I used to live, it basically works as you intended.

The web application is responsible for receiving orders or orders placed by the customer, and the application in the owner's shop is 'listening' to the online database all the time, when the customer places an order / order / budget / I'm writing to a specific bank field.

Logic used on the Web:

pedido = 1
encomenda = 2
orcamento = 3
duvida = 4

In the Desktop application (I used a timer = the previous colleague mentioned, but at a much shorter interval, every 30 seconds I run a Select on the bank that is very small and does not generate any load on the Online Bank):

if (resultado sql do campo especificado) = 1 (ou qualquer outro listado acima) then
begin
  //Aqui eu solicito o Som (sim o som, gravei com uma moça de voz suave o aviso)
end;

The customer who requested me a system of these today has 2 Stores and is already opening a third, and previously already asked for release for use in the third store! His branch of activity is Civil Construction but could be used in any branch!

    
24.10.2015 / 19:00