I'm having trouble understanding how Windows Task Service works. I would like to open a SOAP connection every hour and do its thing.
I came across a few site with how to do it.
1) http://www.redolivedesign.com/utah-web-designers-blog/2007/11/17/how-to-run-a-php-or-asp-file-on-a-schedule-with-windows-xmlhttp-object-and-scheduled-tasks/
2) http://amitdhamu.com/blog/automating-php-using-task-scheduler/
My questions are:
1) which link should I lean toward to?
2) my SOAP connection file is on my server. In the 'Start a Program' in task scheduler, how would I add my ftp script here? or does it have to be in the local machine?
One usually does not "open a soap connection" every once in a while. The SOAP server is running all the time, waiting for requests, so if you want to grab some data from the server, you'd probably "send a soap request every hour" or "make a soap call" as a client.
If the server should only answer requests in a time window every hour, the server would still be running all the time, but the internal code would deny responses beyond "business hours" of that service. Which would be an unusual setup.
So I think you'd really need to run a client script, and that would be easier. First make sure when running the script manually, it does all the things you need. It must be able to run where you need the result.
And then the question is: How to start it automatically, and which operating system is installed on that machine?
Your first link sets up something that sends an HTTP request to a machine. This would work if you have a server, the server has the script, and you have no way to setup a cronjob there, but need the data on that server.
Your second link sets up the script execution on the machine itself. So the script is on that machine, and the data ends up being there, too.
And I cannot answer your second question, because I don't know what your need really is.
Related
I want to set up a WebSocket server using PHP. I have many alternatives to do this, yes, but I wanted to ask people who have experienced which one is more reliable (strong, lightweight, and faultless). I also wrote some code, this code creates a socket server, but I'm not sure how to start it, do I need to open the page from the browser?
Usually a web socket server, as many servers, is started to operate as a daemon in the background and listen there for events coming in. On Linux (Ubuntu) you might create a unit file to be consumed by the system command systemctl, this way the daemon will be started with every boot of the system and you can start and stop it as you need to.
Next you can start it form a command shell like
nohup php websocketserver &
This will send your server into the background an stay there until the system is rebooted. Any output is logged to a file named nohup.
On Windows you better create a service, via a schedule task to have your server start at system boot.
I'm facing a challenge here. My windows 10 PC needs to run all the time, with some programs running on it. However, as a commonplace about windows, it does hang/freeze/BSOD once in a while, randomly. And since I'm not in front of it all the time, sometimes I won't know that it's stuck, for long, till I check it and have to manually hard restart it.
To overcome this problem I'm thinking of an idea like this:
Some program (probably .bat file) can be set to run in the PC, that sends a ping (or some message) to a webservice running remotely, every 10 mins or so.
A PHP script (the webservice) running in my host server (I own a hosting space for my website) can listen to this particular ping (or message), and wait.
If this webservice doesn't receive the ping (or msg) when expected, it simply sends out an email notifying the same.
So whenever the windows hangs/freezes, that .bat file would stop sending as well, triggering the notification from the websvc in the next 10 mins.
This is an idea, but frankly I still don't know how to actually achieve it technically, and whether it's truly feasible. Also, I'm not sure if I'm missing something crucial in terms of server load, etc.
Would greatly appreciate any help with the idea, and if possible pointers to the script that I can put on the server. Also, I'm not sure how to set it up to listen continuously.
Can someone please help here?
What about this?
Have your web service on your host comprise of one page, one database and one cron job.
The database has one table with one record that holds a time.
The cron job checks the the database-table-record every 10 minutes and if the time in the record is in the past, the cron sends you an email.
The page, when requested, simply updates the record to be the current time + 10 minutes. Have your Windows machine request this page every 10 minutes.
So essentially, the cron job is ready to send you an email, but it never can because the PC is always requesting a page to reset the time - until it can't.
Alright, so here's how I Finally achieved this whole idea, as suggested by #Warren above.
Created a simple db table in mysql in my hosting server, with just 2
fields, id and next_time.
Created a simple php page, which inserts/updates the current time + 10mins into the above table.
Created a python script, that checks in this table, if the time stored is < the current time. If yes, then sends a mail to me.
Scheduled this python script as cron job to run every 10 mins.
Thus when the PC hangs, for more than 10 mins, the script would let me know.
Thanks a lot for the help in coming up with this plan. Hope this helps someone else thinking of a similar thing to do.
Improvisation: I moved the above codes to my local raspberry pi web server, to remove dependency on the remote hosting server.
Next step: I'm planning to let the python script on the raspberry pi control a relay, which would toggle the reset switch of the PC, when the above event happens. So, not only would I know when the windows goes on BSOD, but it'll also be restarted on it's own.
Well, as a next step, I made some more simplification to the solution for the original requirement.
No more PHP now. Just one Python Script, and a small hardware improvement.
As I'm still learning new ways with this Raspberry Pi, I now connected the RPi to the PC via ethernet cable as a peer-to-peer connection.
Enabled ping response from Windows, as per this link.
Then wrote another python script to simply ping the windows PC (with a static IP for ethernet adapter)
If the ping fails, then send the email as the earlier script.
As earlier, setup this new script as the cron job to run every 10 mins, instead of the earlier script.
So if the windows hangs, I assume the ping would fail too, and thus an email would be sent out.
Thus now the web-server and database are both eliminated from the equation.
Still waiting for the Relay module to arrive, so I can implement the next step of automatic hard reboot.
I have an App service in Azure: a php script that makes a migration from a database (server1) to a another database (azure db in a virtual machine).
This script makes a lot of queries and requests, so it takes a lot of time and the server (App service) returns:
"500 - The request timed out. The web server failed to respond within
the specified time."
I found that it's something about "idle timeout." I would like to know how to increase this time.
In my test, I have tried the following so far:
Add ini_set('max_execution_time', 300); at the top of my PHP script.
App settings on portal: SCM_COMMAND_IDLE_TIMEOUT = 3600.
But nothing seems to work.
After some searching, I found the post by David Ebbo, as he said:
There is a 230 second (i.e. a little less than 4 mins) timeout for
requests that are not sending any data back. After that, the client
gets the 500 you saw, even though in reality the request is allowed to
continue server side.
And the similar thread from SO, you can refer here.
The suggestion for migration is that you can leverage Web Jobs to run PHP scripts as background processes on App Service Web Apps.
For more details, you can refer to https://learn.microsoft.com/en-us/azure/app-service-web/web-sites-create-web-jobs.
I'm getting into Web Sockets now and have been successfully using the online websockets Pusher(didn't like it) and Scribble(amazing but downtime is too frequent since it's just one person running it).
I've followed this tutorial http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/ on my localhost and it works great!
What I wanted to ask is, how do I setup the server.php from the above file to run as a websocket server on an online webhost/shared server?
Or do I need to get a VPS (and if so, which one do you recommend and how can I setup the websocket server there as I've never really used a VPS before!)
Thank you very much for reading my question and answering. I've read all other question/answers here regarding sockets but haven't been able to find the answer to my above questions yet. Hopefully I find it here!
This is tricky.
You need to execute the server.php script and it needs to never exit. If you have an SSH access to your shared server, you could execute it just like they do on the screenshot and make it run as a background task using something like nohup:
$ nohup php server.php
nohup: ignoring input and appending output to `nohup.out'
After invoking this (using the SSH connection), you may exit and the process will continue running. Everything the script prints will be stored into nohup.out, which you can read at any time.
If you don't have an SSH access, and the only way to actually execute a PHP script is through Apache as the result of a page request, then you could simply go to that page using a browser and never close the browser. But there will be a time out one day or another and the connection between you and Apache will close, effectively stopping the server.php script execution.
And in those previous cases, a lot of shared hosts will not permit a script to run indefinitely. You will notice that there's this line in server.php:
set_time_limit(0);
This tells PHP that there's no time limit. If the host made PHP run in safe mode (which a lot of them do), then you cannot use set_time_limit and the time limit is probably 30 seconds or even less.
So yes, a VPS is probably your best bet. Now, I don't own one myself, and I don't know what's a good/bad price, but I'd say HostGator seems fine.
I am not sure on any of the technical terms, but I think I am describing this in an understandable way.
I am going to write a php script which will listen on a port, and send out data as necessary, i.e. a basic game listening process. There are many places on the web with hints about this, so I think I will be alright there, but any further suggestions on tutorials are welcome.
That is not my question. This is:
What I want to do is have a server where this script is NOT automatically running. What I want instead is when someone fires up the game on their client, it will do a test to see if there is a listening script running already on my server, and if not it will launch it. (I am not sure how to do that yet, but I don't expect that to be too hard. Just send some data to that port and see if there is a response.)
Then when other people join, they will see the script running on the server and use that rather than launching their own.
Are there problems with this idea?
If the first person quits, will the script close down?
Would it be better to let the 'first player' launch the script and put a requirement on the script that it does not shut down. (I.e. the script will run forever until the server gets a restart - basically my server does not mind me running long running scripts, as long as they don't use too much processing, but they don’t allow me to have scripts to start-up if the server is relaunched.)
Would this run-forever script avoid any 'first-player' shutdown problem?
If two people are deemed the 'first player' when they do a check to see if the script is running, but then one of those people launch the script milliseconds before the other, surely this will create two scripts on the server, causing a kind of echo effect for listening. How would I overcome this?
Jon