Yrrussaj, French
@Yrrussaj@piaille.fr avatar

Salut la communauté. Une petite idée de comment on pourrait récupérer localement le contenu d'un fichier toutes les 10 secondes sur un serveur pour l'afficher sur un site qui tourne sur sur ce même serveur. C'est en gros le nom d'un artiste et d'une chanson diffusée en live sur une radio, et on veut l'afficher sur la page web de la radio.

On peut fait ça en quoi ? En ? Avec un plugin ? Et s'il y a 1000 personnes qui accèdent au site en même temps, comment on fait pour éviter de faire 1000 fois la même requête ?

Crell,
@Crell@phpc.social avatar

@Yrrussaj You need JS for that.

Option 1: The client polls for the data. Have a route it can poll that will return just the bare minimum data, and put a 10 second cache lifetime on that response. (Make sure it is cached by your CDN.)

Option 2: Websockets, using ReactPHP or similar, so you can push updates to clients every 10 seconds.

Yrrussaj,
@Yrrussaj@piaille.fr avatar

@Crell Thank you. I'll try a bit of PHP to retrieve the content of the file an put it into a json, and a bit of AJAX to regularly poll that json and put it into a div. Would that make sense ? I'm not familiar with all of this, so REACT and so on seems too complicated for me for that purpose :)

Crell,
@Crell@phpc.social avatar

@Yrrussaj That should work, yes. Make sure your caching is set up properly to avoid hammering your server to death.

If you don't need auth, you could also have PHP just generate a JSON file on disk on a 10 second cron (or whatever schedule), and then serve that file statically. Bypass PHP entirely. Again, need to configure the cache in your web server very carefully for that one file.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • wordpress
  • cubers
  • DreamBathrooms
  • ethstaker
  • magazineikmin
  • thenastyranch
  • ngwrru68w68
  • Youngstown
  • slotface
  • modclub
  • love
  • kavyap
  • everett
  • InstantRegret
  • mdbf
  • megavids
  • khanakhh
  • tacticalgear
  • osvaldo12
  • rosin
  • tester
  • GTA5RPClips
  • cisconetworking
  • Durango
  • Leos
  • normalnudes
  • anitta
  • provamag3
  • JUstTest
  • All magazines