Ping send with PHP [duplicate] - javascript

This question already has answers here:
Creating a ping uptime service with PHP
(3 answers)
Closed 4 years ago.
I have an application to develop for the university. Something simple. But I'm inexperienced on how to do it. It's exactly what I want to do; If I send ping 50 IP addresses at 3 minute intervals, I would like the IP address to write on the admin panel off if it is turned off and open if it is turned on. (red and green button maybe ) How ı can do it exactly? Since the servers belong to us, I want the commands to work correctly. What exactly do I want to show on the screen if Ping is successful?

You can quickly use the hostsystems ping-command by using shell-execution, if available. So you don't have to implement your own php-ping-service as described in the other solution. This can be done if easier solutions don't work. In my opinion less code is always better.
<?php
$output = shell_exec('ping www.stackoverflow.com');
echo "<pre>$output</pre>";
?>

Related

Microsoft QnA maker - Custom message if "no good match found" more than once

I am building an Azure BOT using node.js that connects to the QNA Maker to serve answers.
What I would like to do is to be able to treat the cases when for multiple times the bot would send back an answer with no match found.
Maybe not the first time, but if let's say for 3 times in a row the answer is not found, the bot should propose to connect to human operator.
I guess I would need to do while loop, and put a counter . However is not really clear to me how to treat the answers from the QnaMaker.
Do you have some examples, pseudocode?
Thanks!

Backend increment counter PHP or javascript [duplicate]

This question already has answers here:
PHP Increment a counting variable in a text file
(5 answers)
Closed 6 years ago.
After researching I am not really sure which is a matching solution for my project. I want a serverside number incr. counter, that daily resets.
Every website vistor should see the same number of the counter. Is there
a PHP script or javascript meaningful? Can I store the daily counts in a txt.-file without using a database like MySql?
It would be helpful if you specified a little further what you are trying to achieve. What is the counter counting? number of visits? number of clicks?
You could store this in a text file. I wouldn'r recommend it thought, it will be bulky and you will run into trouble when several updates takes place simultaneously. A better solution if you want an easy and file-based database, check SQLite.

2 player turnbased game logic [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
JS noob here.. I am trying to come up with a barebones multiplayer turnbased card game. with my current coding knowledge, i can implement according to the following pseudo code..
i have 3 files, index.html, multiplayer.php, gameStatus.txt.
index.html:
player one clicks ready button, which sends 1 to multiplayer.php.
player two clicks ready button, which sends 1 to multiplayer.php.
every 1 sec, repeater() checks if "twoPlayerFound" is returned from multiplayer.php.
if "twoPlayerFound" is returned,
then console.log("two players are online, game begins..")
else
console.log("waiting for another player to join..")
multiplayer.php:
when 1 is posted from index.html, php checks gameStatus.txt
if gameStatus.txt has 0
then overwrite gameStatus.txt 0 with 1;
else if gameStatus.txt has 1
then overwrite gameStatus.txt 1 with 2;
send to index.html "twoPlayerFound"
gameStatus.txt:
either has 0,1, or 2
Q1. how can i reset automatically gameStatus.txt to 0 if the players are no longer online.
Q2. what would be the problems using this implementations?
Q3. Is this the correct way of thinking multiplayer game setup
Thanks..
Q3 - I don't think this is a great way to implement a multi player game setup, why? check answers for Q2.
Q2 - Your file can't handle all the complex scenarios that might came up during the full implementation of the game.
An example: 'How can I reset automatically gameStatus.txt to 0 if the players are no longer online'(yes, that's your Q1), to solve this problem, you should keep a time stamp for each player and update timestamp each time the player contact the server and keep a loop to keep an eye on these time stamps and eliminate the player who haven't contacted you recently. To implement this you have to keep some ID to identify your players and so on...
Also, think about how would you be able to scale this setup,scenarios such as: More than 2 people connecting to your server at once, people trying to play in pair with people they like.
Your game also feels network hungry. What you are trying to do is called AJAX Polling.
My suggestions? For client side, make use of WebSockets in HTML5, also try to do some research on socket.io. Most people would recommend nodejs for backend, but you can also make use of PHP. You should also choose a method to implement sessions for users and game status(this choice very much dependent of your backend tech. stack).

Is there a need to break down mini functions in my node.js controller? [duplicate]

This question already has an answer here:
Node.js and asynchronous programming with Q
(1 answer)
Closed 8 years ago.
I have a controller for say users where I sign up my users. Do I really have to break up the steps of the sign up as below and do they all asynchronously seperately or is one big asynchronous call ok? Each step is kinda dependent on the previous.
validate user
create user
create group
add user to group
login the user
redirect the user.
Please help me understand.
Short version:
Apply low-coupling/high-cohesion principles, no one can tell you what you want or need, you're the only person who knows what you want to achieve.
Long version:
You are asking about architectural choices. There cannot be any good answer to that, you'll have to understand the problem yourself depending on other constraints you may have in your system and then apply OO design principles like SOLID/GRASP to understand the side effects of your choices and based on the software qualities you want to obtain take compromises that lead to useful solutions.

How to find client's IP Address using Javascript code [duplicate]

This question already has answers here:
How to get client's IP address using JavaScript? [closed]
(31 answers)
Closed 9 years ago.
I want to find client's IP Address when accessing my app..How to find using javascript code..kindly provide help with sample code..I tried wit tis code but m not getting
function getip(json){
alert(json.ip); // alerts the ip address
}
You can't using ONLY JavaScript on it's own. You need to use a server side script ans call it using Ajax to perform this task.
For example in PHP script, you can do the following to get the client's ip address:
echo $_SERVER["REMOTE_ADDR"];
Next call this script using Ajax and display/use it in your page.
At least there used to be a way using Java to do this, but Javascript alone cannot find a machines IP.

Categories

Resources