[PHP] Opening two pipes simultaneously fails

Saeven

Verified User
Joined
Jun 29, 2003
Messages
76
Hello,

First let me mention that we do not have root access to the box in question, and if the source of our problems is a reseller setting (since we have reseller access only) please let us know so that we can tell the responsible people.

We have a script that opens two pipes simultaneously, and this script works in every instance we have tried it, except for on this one DirectAdmin box that we are resellers under 2AT on.

Here is an explanation, and problematic code.

This code should not be problematic, you can see it in action here:

http://saevenstar.net/test.php


However, it is stalling on the server in question and this is handicapping us something fierce. It often occurs that simultaneous pipes (exactly two) must be opened. When trying to do so, the server "times out". One pipe works fine, so I suspect there is a limit somewhere.

Here is a page with the problematic code http://saeven.net/test.php which is as follows (very simple) :

Code:
<?php
	error_reporting( E_ALL );
	ini_set( 'display_errors', 1 );

	function garbage( $length ){ 
		srand(date("s")); 
		$chars = "abcdefghijklmnopqrstuvwxyz1234567890"; 
		$string = ""; 
		
		while( strlen( $string ) < $length ){
			$string .= substr( $chars, rand() % strlen( $chars ), 1 ); 
		}
			
		return $string; 
	} 
	
	/*
	 * Compares two lines and returns index of first difference greater than 1.
	 */
	function compare( $l1, $l2, $garbage ){
		if( !strcmp( $l1, $l2 ) )
			return "";

		if( !strlen( $l2 ) )
			return "";
			
		$list  = explode( " ", $l2 );		
		$c = count( $list );
		
		$count = 0;

		while( $count++ < $c ){
	
			if( !isset( $list[$count] ) )
				$list[$count] = "";
			$check_str = $list[$count - 1]." ".$list[$count];
			
			if( !strstr( $l1, $check_str ) )
				if( !strstr( $check_str, $garbage ) )
					return $check_str;
		}		
		return "";
	}


	$count   = 1;		
	$tld     = "ca";
	$garbage = garbage( 12 );
	
	if( ($fp1 = @fsockopen( "whois.cira.ca", 43, $errno, $errstr, 30 )) ){
		fputs( $fp1, "google.ca\r\n" );
		$fp2 = fsockopen( "whois.cira.ca", 43, $errno, $errstr, 30 );
		fputs( $fp2, "$garbage.".$tld."\r\n" );
	}
	else{
		echo "<b>Couldn't open socket connection to whois.cira.ca, check that the server exists manually and that your PHP settings permit this operation.<b><br>";
		exit;
	}

	
	while ( !feof( $fp1 ) && !feof( $fp2 ) ) {
		$b1 = fgets( $fp1, 4096 );
		$b2 = fgets( $fp2, 4096 );
	
		$diff = compare( trim($b1), trim($b2), $garbage );
				
		if( $diff ){
			echo "Found diff to be ".$diff;
					
			fclose( $fp1 );
			fclose( $fp2 );
			exit;
		}
		
		$count++;				
	}
	
	echo "no difference found";
	fclose( $fp1 );
	fclose( $fp2 );
?>


Could it be a limitation imposed through DA on my reseller?

Regards.
Alexandre
 
Back
Top