0

I have this script that i am trying to run with nohup ./RunReadMessages.sh & and i am having problems with the messages being delayed, On one server this runs fine but if it's ran on more then one server it gets a big delay when it goes from message 3 back to message 1, Someone told me i should use threading could someone explan to me how i would do that with this script? Just a update: When i run this script by cron there is no delay, can someone tell me if it would be ok to run this script with cron and not nohup? I am not sure if the messags can catch up with running it as a cron job.

<?php
// File For checking messages version 1.0
define("INCLUDE_CHECK", true);
include "../classes/config_inc.php";
include_once('../classes/q3rcon.php');

mysql_connect("$db_host", "$db_user", "$db_pass") or die(mysql_error());
mysql_select_db("$db_database") or die(mysql_error());
$sql="SELECT * FROM {$db_prefix}_servers where Status='Online'";
$result = mysql_query($sql);
while ($data = mysql_fetch_assoc($result)) {
$svip = $data['ip'];
$svport = $data['port'];
$svrcon = $data['rconpass'];

$message1 = $data['message1'];
$message2 = $data['message2'];
$message3 = $data['message3'];

$r = new q3rcon("$svip", "$svport", "$svrcon");

$r->send_command ("say $message1");
sleep(30);
$r->send_command ("say $message2");
sleep(30);
$r->send_command ("say $message3");
sleep(30);
}
?>
AndrewR
  • 10,759
  • 10
  • 45
  • 56
lee
  • 1
  • This doesn't look like multithreading... PHP doesn't even officially support multithreading. See more here: http://stackoverflow.com/questions/70855/how-can-one-use-multi-threading-in-php-applications – Martin Konecny May 26 '14 at 02:45
  • Its says it is supported there? This script reads messages from the db and i want to run it on 8 servers but the end delay gets bigger and bigger the more servers that is added. – lee May 26 '14 at 03:03
  • It's unofficial support and a hack. But you aren't using that hack even. – Martin Konecny May 26 '14 at 03:04
  • Anyone have suggestions why it might be delayed so much from message3 back to message1? or any thoughts on a fix for it? – lee May 26 '14 at 03:59
  • @MartinKonecny no, multi-threading in php is not a hack ... – Joe Watkins Jun 02 '14 at 16:09
  • You're right, seems there is a decent library for it now: https://github.com/krakjoe/pthreads – Martin Konecny Jun 02 '14 at 16:28

0 Answers0