I'm using PHP to GET availability data about 80 Users from a CallCenter. I hope to query the CallCenter for the status/availability of each user every 5 seconds and display the results on a Dashboard.
The CallCenter can only be queried via URL for one user at a time and the username is in the url (so the url is not constant). The answer from the CallCenter is in an XML page. I have been using fopen() to read the content of the url / XML as this is always a random generated XML name and thus the query url is pointed to a directory, not the exact xml url.
I have everything working with a foreach loop, where a unique url is used for USER001 and the content of the XML page is read and a variable is updated. Demo code:
User array:
$users = array(
"username" => array("fullname" => "Full Name",
"status" => ""
),
"username" => array("fullname" => "Full Name",
"status" => "")
);
Foreach Loop:
foreach($users as $username => $userstatus) {
$url = 'http://'.$username.':PasswordForUser@serveraddress.com:80/callcenter/'.$username.'/services/callcenter/';
$get = fopen($url, "r");
if ($get) {
while (!feof($get)) {
$status = fgets($get, 4096);
}
fclose($get);
}
if(strpos($status, 'Available')) { $users[$username]["status"] = "Available"; } else { $users[$username]["status"] = "Offline"; }
}
The issue:
I have a jquery script that refreshes the dashboard every 5 seconds and thus every 5 seconds the CallCenter server is queried of all the Users.
This works, BUT the query actually takes over 1 minute to finish the loop and return all the results to the Dashboard page. It is vital that the CallCenter users can see how many users / agents are available at the given time so they know if enough agents are available to handle the CallCenter load.
Possible solution:
What would be the best solution for my case?
What I have thought of is to create a PHP page for each USER. Have a CRONJOB that runs the pages every x hours (to refresh) and a script on the page that loops through the XML query to the CallCenter every 5 seconds. In the end of each loop (every 5 seconds) the user status is sent to and updates a collector page. Every user page sends the results to the collector page and then the Dashboard page fetshes the data to the collector page every 5 seconds.
Is this a "smart" solution? What would you recommend and how would you code it?
(I´m a PHP begginer)