Metahuman Network Posted January 18, 2021 Share Posted January 18, 2021 (edited) Hello! I'm trying to get the number of accounts/users on servers using feeds. Has anyone accomplished this? Basically want to pull number with that feed (ie 10/20 allowed on LA #1 server) and create a variable for a status page. I can probably use stock levels, but I'd rather pull from server usage instead of setting up stock levels for all of those products and fighting suspensions, etc for an accurate reading. Thanks! Edited January 18, 2021 by Metahuman Network 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 19, 2021 Share Posted January 19, 2021 21 hours ago, Metahuman Network said: I'm trying to get the number of accounts/users on servers using feeds. I would have thought it should just be a db query to the num_accounts value from tblservers_remote for the given server ID. 0 Quote Link to comment Share on other sites More sharing options...
Metahuman Network Posted January 20, 2021 Author Share Posted January 20, 2021 That should work! However, trying to pull this from outside of the WHMCS dir. Maybe a hook to pull that and update a separate db at an interval. Site can read from that... 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 20, 2021 Share Posted January 20, 2021 12 hours ago, Metahuman Network said: That should work! However, trying to pull this from outside of the WHMCS dir. that shouldn't matter - the feed will do all the work, e.g querying the db and returning the result to be outputted wherever you need it. 1 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 21, 2021 Share Posted January 21, 2021 at it's most basic, the data feed code would be along the lines of... <?php # Server Accounts Data Feed # Written by brian! use WHMCS\Application; use WHMCS\Database\Capsule; require("../init.php"); /* *** USAGE SAMPLES *** <script language="javascript" src="feeds/serveraccounts.php?serverid=1"></script> */ $whmcs = Application::getInstance(); $serverid = $whmcs->get_req_var('serverid'); $num_accounts = Capsule::table('tblservers_remote')->where('server_id', $serverid)->value('num_accounts'); $max_accounts = Capsule::table('tblservers')->where('id', $serverid)->value('maxaccounts'); if (!is_numeric($serverid) || empty($serverid)) { $accountusage = 'Server ID Not Found'; } elseif ($max_accounts > 0) { $accountusage = $num_accounts.' / '.$max_accounts; } echo "document.write('".$accountusage."');"; and you would call it in the page by using (assuming the data feed file is called serveraccounts.php and checking the relevant path to the file is correct).... <script language="javascript" src="feeds/serveraccounts.php?serverid=1"></script> if the serverid value is valid (e.g it's a number, the server ID of that # exists and it allows more than 0 accounts on it), then it should return "number of accounts / max number of accounts" (e.g 12/200). the output can be expanded to whatever you need it to be (within reason!) - so hopefully if gives you a starting point... 0 Quote Link to comment Share on other sites More sharing options...
Metahuman Network Posted February 9, 2021 Author Share Posted February 9, 2021 Finally getting around to testing this out, thanks! After looking at my database, there are no entries in tblservers_remote. How is that table populated? Where does WHMCS pull these active accounts from? tblhosting? We could probably pull id from server column where domainstatus is active and add up. Any idea on that side? Thanks again for all your help! ❤️ 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 9, 2021 Share Posted February 9, 2021 11 hours ago, Metahuman Network said: After looking at my database, there are no entries in tblservers_remote. How is that table populated? I assumed the cron was filling the database when the usage stats were being updated daily. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.