Warning: fgets(): Failure 'transport read' (-43)?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Warning: fgets(): Failure 'transport read' (-43)?

Post by Wolf_22 »

I'm running into an issue where I keep getting the following warning:
Warning: fgets(): Failure 'transport read' (-43) in C:\www\practice\foobar\test.php on line 66
What's happening is that I'm using PHP to perform remote executions of a specific Bash file whereby I take the console information and use fgets to display it to the browser window. Most of the time, this seems to work without major issues but the warning above makes me wonder. Every time I see it, it's always coming from the following line of code:

Code: Select all

$line = fgets($stdout_stream);
Here's some context code to show where this occurs ($stream comes from ssh2_exec(), which executes the Bash process that is fed IDs needing archived):

Code: Select all

if($stream){
			
			$results = array();//Holds errors, warnings, and other notifications...

			$stdout_stream = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);

			if (ob_get_level() == 0)
				ob_start();
			
			$max_time = 7200;//Allow a 2 hour max Bash execution!!! (We can allow more if necessary...)
			$timer = 1;	
			while(!feof($stdout_stream)){

				$line = fgets($stdout_stream);//TODO: Fix "Warning: fgets(): Failure 'transport read' (-43)" message...

				if($line !== false){
					if(trim($line) !== ''){
						
						//General FATAL Condition...
						if(strpos($line, 'Fatal') !== false){
							print 'A fatal outcome has been trapped for '.$id.'!';
						}

						//"Not found" Condition...
						if(strpos($line, 'The specified ID cannot be found') !== false){
							print 'ID '.$id.' was not found in Blackboard!';
						}

					}
				}else{
					/*
						This ELSE condition checks timer against a stalled "ls" stream. If it goes beyond $max_time, we terminate.
						(Otherwise, if this wasn't here, it would go into an infinite stream due to how the faulty feof acts.)
					*/
					$timer++;
					sleep(1);
					if($timer == $max_time){
						//Try to eject if the $max_time is met...
						print 'The archive function could not create the archive and decided to give up (processing went over 2 hours). This is likely due to having a very large amount of content. This ID will be skipped. Continuing...';
						break;
					}
				}

				@ob_flush();//This can sometimes be empty, revealing nasty notice verbiage... The '@' suppresses this but still allows it to run.
				flush();
				usleep(1);
			}

			fclose($stdout_stream);
			@ob_end_flush();
			print 'Finished executing archives!';
			return $results;
		}
The overall process has the tendency of taking a considerable amount of time due to the size of data it processes (archives). The rationale for this PHP process is to apply a web-accessible front-end to alleviate the command line execution of everything (it also assists with handling batch processing better as we have more control over how the "IDs" are fed into it).

Long story short, I'm just not sure how to track down the meaning behind "Warning: fgets(): Failure 'transport read' (-43)". I'm not certain, but I guess it could be caused by needing more time to complete?

If anyone could shine some light on this, I would be especially grateful. Thanks in advance.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Warning: fgets(): Failure 'transport read' (-43)?

Post by requinix »

As a test, try setting up a callback for disconnection to see if/when that's happening.

Code: Select all

ssh2_connect($host, 22, array(), array('disconnect' => function() { print 'Disconnected!'; }))
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Re: Warning: fgets(): Failure 'transport read' (-43)?

Post by Wolf_22 »

The callback wasn't called. (The verbiage "Disconnected!" wasn't displayed anywhere.)
Post Reply