sjwspud Posted June 13, 2008 Share Posted June 13, 2008 I have a very annoying problem when using sockets in PHP to telnet into a remote server. I am wanting to run commands on a remote server, then get the output from the commands, parse the info, and save it to MySQL. Now I am able to do so running a few commands. But when I loop through to do multiple commands, I get a 500 internal server error. Using PHP 5.2.6 and IIS 6. Below is my code that I am using. I tried setting the timeout to 15 minutes (900 seconds), and it still gives me the 500 error. I am completely clueless now on how to get this to work. while ($rc = $db->db_object($rs)){ // Open our socket, we will open and close for each command... $fp = pfsockopen($telnet_server,23,$errno,$errstr,$timeout); // Login... fputs($fp, $header1); sleep(1); fputs($fp, $header2); sleep(1); fputs($fp, "$telnet_username\r"); sleep(1); fputs($fp, "$telnet_password\r"); sleep(3); fputs($fp, "$command1\r"); sleep(1); fputs($fp, "$command2\r"); sleep(1); fputs($fp, "$command3\r"); sleep(1); fputs($fp, "$command4\r"); sleep(1); fputs($fp, "$command5\r"); sleep(1); fputs($fp, "$command6\r"); sleep(1); fputs($fp, "exit\r"); sleep(1); // Grab the command output... $read = fread($fp, 128); $pos = socket_get_status($fp); $read = fread($fp,$pos["unread_bytes"]); $read = str_replace("\n","<br>",$read); $explode = explode("\"",$read); // Close the socket connection... fclose($fp); In the code above, I am looping through all records in my database. I am running 6 different commands each time I loop. Below is what I am sending for headers - aka - $header1 and $header2 $header1 = chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).chr(0x27).chr(0xFF).chr(0xFD).chr(0x01).chr(0xFF).chr(0xFB).chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).chr(0x54).chr(0x45).chr(0x52).chr(0x4D).chr(0xFF).chr(0xF0); $header2 = chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).chr(0xFC).chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).chr(0xFF).chr(0xFC).chr(0x21); Please help me out with this issue. I would really appreciate it. I have been pulling my hair out to get this working. Link to comment https://forums.phpfreaks.com/topic/110010-telnet-using-php-sockets-500-internal-server-error/ Share on other sites More sharing options...
btherl Posted June 13, 2008 Share Posted June 13, 2008 Can you create a log file in order to find the exact line where the error is occurring? I assume you have display_errors set on already. Have you tried running the code for a single db result only, rather than for all in one script run? Link to comment https://forums.phpfreaks.com/topic/110010-telnet-using-php-sockets-500-internal-server-error/#findComment-564562 Share on other sites More sharing options...
sjwspud Posted June 14, 2008 Author Share Posted June 14, 2008 I have tried running a single db result, and it works perfectly. But when I loop through multiple records, it ends of having a 500 error. I didn't have display errors on before hehe, but I turned it on and this is what it gave me... Fatal error: Maximum execution time of 30 seconds exceeded in C:\Inetpub\wwwroot\amrt\sources\class_index.php on line 321 I tried ini_set("maximum_execution_time","300"); and still get the same error. I am wondering what I need to set to change the execution time from 30 seconds to at least 300 seconds. Link to comment https://forums.phpfreaks.com/topic/110010-telnet-using-php-sockets-500-internal-server-error/#findComment-565374 Share on other sites More sharing options...
sjwspud Posted June 14, 2008 Author Share Posted June 14, 2008 I wanted to let you all know I fixed this issue. What you have to do to up the execution time is to do the following command... set_time_limit(valuehere); I set it to 300, and the script never caused a fatal error afterwards. Just wanted to post this in case anyone else were to run into it. Link to comment https://forums.phpfreaks.com/topic/110010-telnet-using-php-sockets-500-internal-server-error/#findComment-565376 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.