The server has a data repository (directory in which text files) to which the site should be accessed. But the fact is that for one reason or another it is inaccessible.
Therefore, it is necessary to organize a server availability check, so that a message is displayed after, say, seconds 15: "I can not connect to name_server".
How to organize such a check?
|
3 answers
I solved the problems in a very simple and not so reliable way, but for the first time let it be like this:
$url = '//mypage/www/html/test_b.ru/www/opr/admin/store/V6/000Admin/history.txt'; // пробуем открыть файл для чтения if (fopen($url, "r")) { //echo "<p><font size='3,5' color='black'> <b>Server is available. </b></font></p>"; } else { echo "<p><font size='3,5' color='black'> <b>Server is not available. </b></font></p>"; } fclose ($url);
Thank you all for your help.
|
<?php $server = 'localhost'; $user = 'dbuser'; $password = 'dbpass'; $dblink = mysql_connect($server, $user, $password); if($dblink) echo 'Соединение установлено.'; else die('Ошибка подключения к серверу баз данных.'); $database = 'dbbase'; $selected = mysql_select_db($database, $dblink); if($selected) echo ' Подключение к базе данных прошло успешно.'; else die(' База данных не найдена или отсутствует доступ.'); ?>
Read more here http://rtfm.co.ua/php-mysql-proverka-soedineniya-s-serverom-i-podklyucheniya-k-baze/
ps Maybe I did not understand you correctly. Answer in the comments correct the answer. Explain what you mean by servers.
Show how you connect, throw off an error which gives you if the server does not respond
- Thanks, probably, I myself from ignorance misinform everyone. The fact is that the server is just a directory with files (pdb files are stored). They can be viewed or deleted already obsolete from the site. So I probably need the first part (before databese). And is it better to implement a separate script or in index.php you can add? Is it possible to do this somehow via
get_headers
? Suppose if the answer is 200, then OK, we work further, and if not 200, then the message to deduce that a bummer? - Yulenka - Damn, only this again is more likely to check the existence of the file, and not just a connection. On the other hand, if the test passed with a positive status, then the server is also available. Right? - Yulenka
- one@Yulenka, through get_headers you can (could not understand you correctly). Make a check and if the answer is 200 then all the rules. To create a separate file or to do everything in one, then as you prefer (there are no strict rules, I would probably do it separately but not a fact). The second comment is not entirely clear. - Deno
- It is not necessary in 2016 to propose using the outdated extension
mysql_
- Dmitriy Simushev
|
example.com
- sanmai