0
votes

I have some PHP script that takes lots of time to execute (large amount of data to process).

Is there a way to offload the server by making some php functions execute in client-side (the browser) and than give the result to server side ?

Example: in my script I have a portion that does a file_get_contents and this one takes many seconds to execute...

can it be possible that this file_get_contents be executed in client-side, than give back the calculated result to the server ?

Like a distributed computing mechanism ?

If there is a solution that ask the permission of the user, I'm ok with that also.

3
Can you copy here a part of your code? - driconmax
No, PHP is a server-side language. If you want to do stuff on the client, have the PHP script return a page with Javascript in it. - Barmar
You can't execute file_get_contents on the client, because the client can't access files on the server. - Barmar

3 Answers

0
votes

If your code is processing data received from, for example, a db, you can make the data process in javascript on the client side, and using php only to retreive that db info

0
votes

You can cache the result of file_get_content function into a file and use the content from the cache file later.

-1
votes

You'll need to do some extra steps such as running JavaScript or sending the user an executable to have them do any processing for you!

However, in your case it seems like your speed is limited by reading a particular file, so you can likely only speed up this operation locally.

If possible, cache frequently-read files in memory to return them much more quickly than reading from the disk every time for every request. You may even wish to make requests to another program to do this for you.