I am trying to write a small script to do a dictionary definition lookup for multiple words at a time. Right now, I am my wits end trying to figure out why my very simple script won't work. I am connecting to a local dict server at 192.168.4.4 but that could be replaced with dict.org very easily. The script used to work and returned definitions, but it has stopped doing so, and I haven't upgraded my Apache, or PHP. Any help would be greatly appreciated.

P.S. there is another page with a textarea that feeds $_POST['words']

<?php
	if (isset($_POST['words'])) {
		$words = trim($_POST['words']);
		$words_sep = explode(",", $words);

	$socket = fsockopen("192.168.4.4", "2628", $errorno, $errorstr, 90);
	$server_send = fgets($socket, 6144);
	echo $server_send;

	$query = "DEFINE * %s";
	$regex_def_num = "^[0-9]{3} ([0-9]+) .+";
	$regex_word_info = "^[0-9]{3} \"([^\"]+)\" ([^\" ]+) \"([^\"]+)\"";

	for ($i = 0; $i < count($words_sep) ; $i++) {
		$format_query = sprintf($query, $words_sep[$i]);
		echo $format_query;
		if (fputs($socket, $format_query) === false) {
			echo "Could not write Command!";
			die;
		}
		$respond = fgets($socket, 6144);
		if ($respond === false) {
			echo "Error";
			die;
		}
		ereg($regex_def_num, $respond, $reg);
		print_r($reg);
     	$def_num = (int) $reg[1];

		for ($j = 0 ; $j < $def_num; $j++) {
		    $respond = rtrim(fgets($socket, 6144));
			if ($respond === false) {
				echo "Error";
				die;
			}
			ereg($regex_word_info, $respond, $reg);
			$word = $reg[1];
			$dictionary = $reg[3];
			$definition = "";
			while ($current = fgets($socket, 6144)) {
				if (ereg("^\.\r\n$",$current)) {
					break;
				}
				$definition .= $current;
			}
			echo $definition."<br><br>";
		}
	}
}	else {
	header("location:index.php");
}


?>	


    What do you mean "stopped working" ? Is anything returned? Is display_errors set to On and error_reporting set to E_ALL? If so, does PHP output any messages at all?

      All error reporting is on. The out consists of the $server_send and the $format_query, but no $definition values are output. The script usually takes a loooong time to execute, I think an fget is locking up, and then a single "Error" is echoed and the script dies.

      220 armon-lamp.elitewm.local dictd 1.10.2/rf on Linux 2.6.17-11-server <94.7264.1179610847@armon-lamp.elitewm.local> DEFINE * venalError

      Is a sample output.

      EDIT:
      B.T.W. I used a desktop based client software to make sure the dict server was working, and it is. One less possilble source of problems

        Write a Reply...