Send a file from a PHP page to another

I need to send a file from one PHP page (to which the client uploads files) to another PHP page on another server, the files will be permanently saved.

To contact us, I use the JSON-RPC protocol; Is it wise to send the file this way?

$string = file_get_contents("uploaded_file_path"); 

send the string to the remote server and then

 file_put_contents("file_name", $recieved_string_from_remte); 

I understand that this approach takes twice as much time as downloading directly to the second server.

thanks

[edit]

Details:

I need to write a service that allows a php user (maybe joomla) to use a simple api to upload files and send other data to my server, which analyze them, put them in db and send a response

[change]

I need to create a simple method that allows the end user to do this, who will use this interface on server 1 (upload), using php and stopping, so the remote ssh mounts strange funny things

+4
source share
4 answers

If I were you, I would send the file directly to the second server and save its file name and / or some hash of the file name (to facilitate the search) in the database on the first server.

Using this approach, you can request the second server from the first for the status of the operation. Thus, you can leave the file processing on the second machine and assign user interaction with the first machine.

+1
source

As I said in my comment, THIS DOES NOT RECOMMEND, but anyway ....

You can use sockets that read bytes byte: http://php.net/manual/en/book.sockets.php

or you can use ftp: http://php.net/manual/en/book.ftp.php

Anyway, the problem in your approach makes the process of asynchronization or synchronization with user navigation? I really suggest you pass it on sql or ftp and give the user an answer based on another event (for example, viewing a file, then writing, etc.) or using sql (binary, blob, etc.)

+1
source

If you do not need the files immediately after receiving them (for processing, etc.), you can save them all in one folder on server 1 and configure cron to view the contents of the folder on server 2. All this assumes that you are using servers linux is one of the safest and most effective ways to do this.

For more information see http://en.wikipedia.org/wiki/Secure_copy or google scp.

+1
source

Use SSHFS on machine 1 to map the path of the file to machine 2 (using SSH) and save the downloaded file on machine 2. After downloading the file, start machine 2 to process and report as usual.

This will allow you to download to computer 1, but actually transfer it to computer 2 HD, so that it can be processed faster on this machine.

This will be faster than any solution for copying SQL files or manually, because the file transfer occurs when the user downloads the file.

+1
source

Source: https://habr.com/ru/post/1386586/


All Articles