Udders
Udders

Reputation: 6976

PHP FTP and ajax or similar

I have written a PHP class that allows a user to interact with an FTP server, connect, change directory, upload, etc. What I am wanting to do next is to give the realtime updates of what is happening on the server, ie. if they change directory, throw them a message saying directory changed you are now in {pwd}.

Is this even possible? I am happy with my PHP class, but I have no idea how to give it the realtime aspect.

Upvotes: 1

Views: 197

Answers (2)

Mark Grey
Mark Grey

Reputation: 10257

What you are describing is predominantly a frontend engineering question.

Typically in a browser based UI, these kind of "realtime" situations are simulated with ajax calls that are made to the server at a timed interval using JS. You can set up endpoints that return representations of your "answer" to the ping and update your frontend display with the relevant info. This circumvents the stateless nature of the HTTP protocol.

I would recommend any calls made in this "pinging" manner also update their interval in the event that they receive no new data. Its a lot more efficient to check less often when several consecutive responses show no new information. You can increase the interval every time there is nothing new to report.

There are more advanced implementations when true "realtime" is required, you can google "HTTP Push" for more information on how to hang an HTTP response until new data is sent. I don't think anything this particular would be required in your case however.

Upvotes: 1

Luke
Luke

Reputation: 8407

to simulate realtime updates, you can write a simple javascript code that checks for changes on the server at a time interval. Like a Ping, just return if something new exists or not. if the server returns true, you can fetch all messages.

other approaches, that are getting used more and more are websockets. http://socket.io/ is a helpful example. It is based on node.js

Upvotes: 0

Related Questions