简体   繁体   中英

share php code across servers

Can I share PHP code between two servers? For eg say I have a file A.php on server1 and B.php on server2; is there a way to use B.php in A.php? The purpose behind this is to make sure that some code which I don't want to release publicly sits on my servers and other servers just use it as an when needed.

Let me know if the requirements seem fuzzy, I will try and explain anything unclear.

The best method would be to use ioncube encoding or something similar to protect your code. Going over the network unless its a direct link will slow down every response by a few ms and that ads up quick on a busy website.

Take a look at the PHP docs for include() here . The implication is that you can, with the correct settings on your local server, include a .php file - however, the request for the file will execute it on the remote server so you'd need to ensure that the .php file you're including echo's PHP script. I don't know that this is a particularly good thing to be doing - I can only imagine the performance could end up being dire.

There's two ways to do this.

The first one is to do a remote include . You would include a file from a remote server. This will not hide your source code. You could limit access to that IP address, but you are not protecting your code. Besides it is bad practice and potentially insecure so I would very strongly advise against it.

include 'http://serverb.com/some_file.php';

The other possibility is to use a web service . This means that your remote server provides a service. server1 makes a request to server2, providing it with the data that server2 needs to complete the action. server2 processes the data and generates a response, which is returned to server1. server1 parses the response and does something interesting with it. You can use file_get_contents to do such a request. Ideally you'd serialize the output using json or XML for transmission and easy parsing.

$response = file_get_contents('http://serverb.com/webservice.php?param1=something&param2=something_else');

Note: Web services are slow, the network is a major bottleneck. So you will have to cache the results or do something similar.

No, it's not possible. The web server which runs the php file needs to be able to access the php file to execute it. You can do it if you somehow share the file over the network but then the file will be available to the other server.

If you want to do this to avoid having your code stolen then you should look for PHP encoders and obfuscators.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM