CoolComputing Logo
Coupons/Deals  ·  New Promo Codes/Coupons  · December 16, 2018

Windows Maximum Connections Limit Solution Using PHP

Posted on Tuesday, November 25, 2014 @ 05:33:35 PM CST by David Yee [] [read 5500 times]

PHP Tips and Code Examples

If you are using Windows 8, 7, or XP Pro as a file server and often run into problems where users can't connect to because the 20 or 10 maximum simultaneous connections have been reached (or even fewer connections for the Home versions of the OS) - here is a quick and simple solution via PHP. The script basically uses the command "net session", parses the output and looks for idle connections and disconnects them- in this case if they've been idle for a second or don't have any open files. Combine this with some sort of cron program for Windows, and it works quite well.

//disconnects windows share sessions with any sort of idle time and doesn't 
//have any open files; combine with cron for windows:

$cmd = "net session";
exec($cmd, $out);
$disconnect_these = array();
foreach ($out as $line){
	$line = trim($line);
	if (substr($line, 0, 2) != "\\\\"){ continue; }
	$t = explode(':', $line);
	$idle_time = substr($t[0], -1);
	$open_files = explode(' ', $t[0]);
	$open_files = $open_files[sizeof($open_files)-2];
	if ($idle_time > 0 || !$open_files){
		$computer_name = trim(substr($line, 0, 17));
		$disconnect_these[] = $computer_name;
		#print "$computer_name\t$idle_time\t$open_files\n";
if (sizeof($disconnect_these)){
	foreach ($disconnect_these as $disconnect){
		passthru("net session $disconnect /delete /Y");

Here is the sample crontab entry to run the script, which we're calling disconnect_idle_sessions.php, to run every minute:

* * * * * c:\php\php c:\php\disconnect_idle_sessions.php

Please rate this article or post a brief review of Windows Maximum Connections Limit Solution Using PHP or comment on benchmark/performance, features, availability, price or anything else regarding Windows Maximum Connections Limit Solution Using PHP. Thanks!

Windows Maximum Connections Limit Solution Using PHP Rating: 2.3/5 (20 votes cast)

Your Name:
I have read and agreed to the Review Posting Agreement.
Review Title: