Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
How to use HTML5 SSE with PHP and python

I want to check simple if my API endpoints are alive but I got back Firefox can’t establish a connection to the server at myURL error, I'm on 94.0.1 (64-bit) windows edition, which is based on this is supported. And I'm trying this on AWS-ec2. All of this is based on this article: https://www.w3schools.com/html/html5_serversentevents.asp

This is my HTML:

 <div id="searchDatabases"> 
 </div>
            <script type="text/javascript">
              if(typeof(EventSource) !== "undefined") {
                // Yes! Server-sent events support!
                var source = new EventSource("pingServers.php");
                source.onmessage = function(event) {
                    document.getElementById("searchDatabases").innerHTML = event.data + "<br>";
                };

              } else {
                // Sorry! No server-sent events support..
                console.info("Not supported browser!");
              } 
            </script>

this is in pingServers.php

    header('Content-Type: text/event-stream');
    header('Cache-Control: no-cache');


    $output = shell_exec("python3 pingServers.py")

    echo $output;

    flush();

and this is pingServers.py

#!/usr/bin/python
import requests
import json 
import html
import sys

requestpost = requests.post('MyJSONEndpoint.php')
if requestpost.status_code == 200:
    print('OK')
else:
    print('not OK')

So my question is how can I do this correctly?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda