Can PHP trigger an event on a remote Windows Server - php

Is there a way for PHP to send a signal to a Windows Server to run a script?
I am writing a web application which generates database entries that are later synced by a program on a remote Windows Server. PHP & mySQL are running on AWS.
The application on the windows server syncs the mySql database with Quickbooks. Ideally I would like to send a signal from PHP so that if PHP has updated the database, letting the remote Windows server know which script to run to in order to initiate the sync program. I would need to be pointed in the right direction both on the PHP commands as well as how to setup the listening service on Windows.
I was thinking if I could get Windows to listen on a specific port for a short XML file, PHP could send a password and entity ID number to identify which script to run.
Any suggestions?
Thanks!

You can use php on both end. Just install php server on windows, then when request happened execute a windows command. Php can do that.

I would schedule a task to read a specific file from the windows server side and from the php side you could use cron jobs. This question is too broad though and there are several approaches to that. You need to be more "code" specific.

Related

How to open an external GUI application from web browser using PHP?

I'm new to web development. I'm trying to execute a shell script using PHP's shell_exec(). Inside the script, I'm trying to invoke a GUI application(Qt). When I executed the PHP script from a terminal the application started as expected. But when I opened it from browser an empty blank page appeared.
I'm using Ubuntu with apache2 server running as service. When I searched in google, the similar problem is solved in the Windows environment by allowing apache service to interact with the desktop.
PHP Script:
<?php
$log = shell_exec('sh testcmd.sh');
?>
testcmd.sh:
./Program1
Any help provided will be highly appreciated.
It is somewhat unclear what you're asking.
If you wish that browsing to a certain web site will run a PHP script that will open a GUI app for the client to interact with, the answer is "you can't". The reason is that the way the setup works is that the server and the client run on different machines, and your PHP runs on the server machine. As such, the client never gets to see the running program.
The above is true also for Windows. The answer you quote in your question does not apply to a server running on a different machine than the client.
If, for whatever reason, you want something that works only when the server and client run on the same machine (or there is someone watching the server's display), then you need to do the equivalent of the Windows answer.
The graphics display on Linux (assuming you're not running wayland) is using a protocol called X11. In order for the display to appear, your GUI program needs two things. The first is to know which display it needs to use. This is supplied with an environment variable called DISPLAY. The second is an authorization to actually use that display.
So in order for your PHP script to run a GUI app that will show its GUI, you will need to first do the following steps:
Set the DISPLAY variable to the correct value (copy from your desktop environment).
Run xauth add something, where you can get what something is by running xauth list on your desktop environment.
If you do these two things (in this order), your GUI should show up.

Running websocket server on amazon EC2

I've written a web socket server that listens to a specific port. In order to run it I log in to EC2 instance with putty and run:
php server.php
I was wondering if this is the only and the right way to do. Normally copy my php files to the host via ftp would be enough, I don't understand why the php command needs to run the server.
Any help is appreciated.
This question is not about any particular coding problem, so is considered off-topic in terms of StackOverflow.
The way PHP works - is just a script file. Same as bash (.sh), python (.py), node.js (.js) or any other similar.
They all in fact have to be executed. In common world, Apache, nginx or any other web server will do execute those scripts for you for each request is made to web server.
As you are creating socket file, you need to create it yourself, as it creates one socket and php script will continue working as long as it will by it self. It is not executed per each request. In fact make sure it is not executed by apache so do not put in usual website directory.

Apache file execution model using PHP exec()

Newly registered user here after being a long time lurker!
I have an Apache 2.2 web server running on Windows locally (for now) as a service, with PHP 5 installed. I'm using PHP's exec() to run a command line client (.exe) hosted on the server, which authenticates the user to a database and makes pre-defined SQL queries on behalf of the user.
My question is: How does Apache run programs requested by multiple users through the (same) PHP exec() command? In this case, will Apache be using the same one instance of the client for all users who will access it, or will Apache be creating a new instance of the client for each user?
Since the client was designed for use by a single user, if Apache does reuse the same instance of a client, it will be running into a lot of concurrency issues.
I appreciate any help I can get, thanks!
PHP launches the process every time PHP calls exec(), and it keeps running for as long as it takes to finish. As such, you will end up with multiple copies of the process running at once if multiple users are simultaneously accessing scripts your web site which trigger it.
Unless you are using some really weird sort of database, there is probably a better way to query it than launching a command-line tool. If there's an ODBC driver available for your database, for instance, you may be able to use it directly via the PHP ODBC extension.

how basic server in php works

I want to ask a conceptual question: how a server written in php works?
Actually I want to know when I write a simple php code to get some information from a client, how does the whole process happen?
In java I have to start server first. Server listens to the port. When any client knocks then connection creates. Is it similar to php? Before running client application do I have to run my php code or server will do that for me? I am using localhost.
see this article: http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/
Before running client application do I
have to run my php code or server will
do that for me.
This depends on your server architecture, you can use something like inet.d which invokes your script only if there is access on that port, or you have the standalone version, where you start the php from console und it waits for connections.
Does it similar to php ?
Yes.
Before running client application do I have to run my php code or server will do that for me.I am using localhost.
If you are writing a server in PHP then your PHP code is the server.

schedule task in windows 2008 server for php file

i have shared hosting on windows 2008 server and one project in php.
actually i want to run one php file once in a day automatically...
i want to run one schedule task once
in day.
any php code, jquery or ajax
for information.
i have access to ftp to up load files to my domain but i don't have sever access and its windows 2008 server.
how can i run schedule task in php on windows 2008 server?
Thanks
If you don't have access to the server where you can set a schedule job then below are your probable options:
Create a php file on server W(windows2008) then if you have a free hosting account at server L(Linux) where you can setup cron job, then creating a CURL to access server W would do.
If your page is access often the creating a JS script with setTimeout("myAjaxFunction", 10000) would also do but it's an awkward approach as you assumed that user browser open accessing yoursite somewhere else.

Categories