I'm trying to run an irc bot with cakephp. My problem is referencing the connection, I can pass it through functions but seems a silly solution when I'm writing dozens of functions all requiring the same variable. The way I did it was through a global variable $socket. It seems cakephp doesn't support global variables, at least not in the traditional sense.
Any ideas?
Here's the code:
$socket = fsockopen($config['server'], $config['port']);
The main function I will keep calling is send_data(), which communicates with the server.
function send_data($cmd, $msg = null, $socket = null)
{
if($msg == null)
{
fwrite($socket, $cmd."
");
echo '<strong>'.$cmd.'</strong><br />';
ob_flush();
} else {
fwrite($socket, $cmd.' '.$msg."
");
echo '<strong>'.$cmd.' '.$msg.'</strong><br />';
ob_flush();
}
}
So basically every time I have to call the send_data function, which I do many times, I have to reference $socket. Is there a way to make it persist in cakephp?