Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
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?

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda