Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!