Does curl execute the PHP script on the remote server? - php

This is a fairly simple question, yet I haven't been able to find a simple answer.
If I use curl on Server1 to access a PHP file on Server2, is the code in that file executed on Server2?
I have a script on a remote server that I need to be able to execute from my main server. The code should be executed on the remote server where the PHP file resides.

Yes, it is. Same as you'd enter that address to internet browser.

Related

Let python program on local machine know when server has changed a file on the server

I have a python program that sends an XML to my website when the user changes something on the local machine the python program is running on. I added some stuff on the website so the user can make the changes there and the python program will retrieve the XML file and make the changes on the local machine. The host I'm using for my website doesn't let me use php sockets. Right now I have the python program retrieving the XML file via FTP and checking if there is any change to the file.
I want to know if there's a way for the server to let the program know when it has changed the file or for the python program to detect the change without constantly retrieving the file and without sockets.

Running a PHP script located on FTP server

So I have a php script that connects to a MySQL database that runs fine on my server and my schools server when it is ran. I currently have to have my script connect to another database but get the following error
Host "host" is not allowed to connect to this MySQL server
I did search and found the option to use GRANT ALL PRIVILEGES "." for the user but wanted to know if it is possible (Since I have to submit these files to the persons FTP) to run it after I upload the file to the ftp server. My guess is where the database is located as well. HTML runs fine off the ftp but when I try to open the php script All I see is just the code instead of anything running. Is it impossible to run a PHP script off the ftp using ftp://ftpserver/script.php?
Or am I looking at this the wrong way?
I apologize for any beginner annoyance as I've never really worked with FTP and how they function when it comes to this.
Any help is appreciated.

execution of php script

I know that when we execute a PHP script on localhost, the server runs the code and does the required processing and simply outputs the result to the browser. Recently, I was reading about socket_create function which creates a connection for server and client to communicate, but I have a doubt regarding it. Below is what I think, please correct me if i am wrong.
When I run my program (which uses socket_create) by typing http://localhost/myprog.php... The prog commands localhost to make a open a socket. This is ok, but what if I want to create socket on some other server? (Below are two options, please tell me which is correct)
If I still run the script on http://localhost does that mean the
script will run on localhost and localhost will make a socket on the
other server? And if I want to give some input to the other server
the input will pass through localhost.
I can't do it as told above, I would have to run my script on other
server to create a socket on it.
PHP script is like any other program on machine. If you access script which is on localhost, and this script creates socket then script on your local machine connect to the other server, retrieves output, pass it back to script. If you access some remote host, then script is executed on this remote host - that's only difference.
So the answer is 1.

Alternative to ftp_exec()?

Is there any way to have one server call and execute a script on another server? I have tried ftp_exec(), but the server does not support it. Here is what I am trying to do.
Server 1 creates and uploads a zip file to Server 2. Server 2 then unzips and extracts the file.
Currently I have scheduled cron jobs at alternating times, one on each server in order to do this. Ideally I would like Server 1 to be able to do everything, sending a message to sever 2 telling it to unzip and extract the uploaded file.
Is it possible to do something on Server 1, like exec(php ftp://user:password#server2/unzip.php) ?
Is it maybe possible using CURL?
FTP = File Transfer Protocol. It's not intended (and should never be used for) remote execution. If you need to trigger a remote script, use HTTP. It's easy enough to do
$stat = file_get_contents('http://example.com/unzip.php');
to invoke the remote PHP script to do the unzipping. If you need authentication on the URL, you can set up a stream or use CURL instead.
Does your sever support ssh or have you the ssh account?
You can run remote commands via ssh.

PHP - Specifying server for exec'd command to be run on

Using PHP, exec('php test.php'); will execute a separate PHP script on the command line.
What if test.php lives on another server, but within the same network? Can I specify that server's local IP address for the shell command to be run? What about a remote IP address? I could always install Apache on the second server and call the remote script via http, but would like to avoid that if possible.
Thanks, Brian
I can think of two options:
Use exec() to execute a program that connects to this other server and does whatever.
Set up a web service on the receiving server, and have the sending server send a request.
Regardless of what you choose to do, you'll need some setup on the receiving end, for the obvious reasons Dan Grossman pointed out.

Categories