RE: [PHP-ES] Problemas con Script en Php al dejarlo en background.
| From: | PHP | Date: | Mon, 13 Oct 2003 14:17:56 +0000 |
| Subject: | RE: [PHP-ES] Problemas con Script en Php al dejarlo en background. | ||
| References: | 1 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-41518@lists.php.net to get a copy of this message | ||
Me lo arregle solo..
Les digo por si les pasa, no puedo hacer echo "Funcionado"; y cerrar la
Terminal, por que no tiene adonde hacer el echo, asi que hice un log.txt y
listo.
-----Mensaje original-----
De: PHP [mailto:php@barrahome.org]
Enviado el: domingo, 12 de octubre de 2003 20:21
Para: lista@phpes.com
Asunto: [PHP-ES] Problemas con Script en Php al dejarlo en background.
Hola, tengo un script en php que corre en mi Server, para que el resto de
mis otros servers reporten la carga de los mismos, es un Server, utiliza
sockets y demas, la cosa cuando hago php script.php & y cierro la Terminal
(Shell) se muere. Alguien me lo puede inspeccionar?
<?php
require_once("/home/uptime/public_html/config.php");
set_time_limit(0);
// Open socket
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($socket, _UDPIP, _UDPPORT);
echo "Waiting for connections...\n";
flush();
do
{
if ($rawdata = socket_read($socket, 255))
{
$error = false;
// auth_id|uptime|load|idle|os|oslevel|cpu|client
$data = explode("|", $rawdata);
$authid = substr($data[0], 0, 32);
$uptime = substr($data[1], 0, 16);
$load = substr($data[2], 0, 8);
$idle = substr($data[3], 0, 8);
$os =
htmlspecialchars(strip_tags(substr($data[4], 0, 32)));
$oslevel =
htmlspecialchars(strip_tags(substr($data[5], 0, 32)));
$cpu =
htmlspecialchars(strip_tags(substr($data[6], 0, 48)));
$client =
htmlspecialchars(strip_tags(substr($data[7], 0, 48)));
// Make sure we don't confuse cpu and client (this happens
sometimes)
if (trim($client) == "")
{
$client = $cpu;
$cpu = "";
}
// Validate the incoming data
$result = $db->query("SELECT id, name, last_heard FROM hosts
WHERE auth_id = '$authid'");
if (count($result) == 0)
error_exit("Invalid auth key or auth key not
specified", true);
if ($uptime < 0)
error_exit("Invalid uptime or uptime not
specified");
if ($idle != "" && ($idle < 0 || $idle > 100))
error_exit("Invalid idle value - must be an integer
between 0 and 100");
if ($load == "")
$load = "0.00";
if ($idle == "")
$idle = 0;
if ($error === false)
$host = $result[0];
// Sending reports too often?
if ((time() - $host->last_heard) < 30)
error_exit("Reports should not be sent more than
once every 30 seconds. Slow down.");
if ($error === false)
{
// What was the last uptime reported by this host?
$result = $db->query("SELECT id, uptime FROM uptimes
WHERE hostid = '$host->id' ORDER BY reported DESC LIMIT 1");
$data = $result[0];
// Is the new uptime less than the last reported
uptime? If so, log a reboot
if (count($result) > 0 && $uptime >= $data->uptime)
{
// Update uptime data
$db->execute("UPDATE uptimes SET reported =
".time().", uptime = $uptime, cpu_load = '$load', idle = '$idle', os =
'$os', osl
evel = '".urldecode($oslevel)."', cpu =
'".urldecode($cpu)."', client =
'$client' WHERE id = $data->id");
}
else
{
// Insert new uptime data, log the reboot
$db->execute("INSERT INTO uptimes (hostid,
reported, uptime, cpu_load, idle, os, oslevel, cpu, client) VALUES
($host->id, ".t
ime().", $uptime, '$load', '$idle', '$os',
'".urldecode($oslevel)."',
'".urldecode($cpu)."', '$client')");
$db->execute("UPDATE hosts SET last_reboot
= ".time().", reboots = reboots + 1 WHERE id = $host->id");
}
$db->execute("UPDATE hosts SET last_heard =
".time()." WHERE id = $host->id");
// Yay!
echo "[".date("H:i:s")."] $host->name reporting
in...";
flush();
error_exit("Success");
}
}
$result = NULL;
$data = NULL;
$rawdata = NULL;
unset($result, $data, $rawdata);
} while (1);
function error_exit($msg, $authError=false) {
global $db, $error, $authid, $host;
$error = true;
if ($authError === false)
$db->execute("UPDATE hosts SET lasterror =
'".mysql_escape_string($msg)."' WHERE id = $host->id");
echo $msg."\n";
flush();
}
?>
---------------------------------------------------------------------
Archivo On-line: http://www.phpes.com/
via news: news://news.phpes.com/
Manual PHP en espaqol: http://www.php.net/manual/es/
Para dar de baja la suscripcisn, mande un mensaje a:
lista-unsubscribe@phpes.com