agentile / PHP-Stanford-NLP

PHP interface to Stanford NLP tools (POS Tagger, NER, Parser)
168 stars 51 forks source link

proc_open for slow process in windows #8

Open ghost opened 9 years ago

ghost commented 9 years ago

$descriptorspec = array( 0 => array("pipe", "r"), // stdin 1 => array("pipe", "w"), // stdout 2 => array("pipe","w") // stderr );

$process = proc_open($cmd, $descriptorspec, $pipes, dirname($this->getjar())); //$cmd is java -mx300m -cp ^"postagger^\stanford-postagger.jar^;^" edu.stanford.nlp.tagger.maxent.MaxentTagger -model C:^\wamp^\www^\yii^\basic^\views^\site^\postagger^\models^\english-left3words-distsim.tagger -textFile C:^\Windows^\Temp^\pos1D8A.tmp -outputFormat slashTags -tagSeparator ^#^# -encoding utf8//

if(is_resource($process)) { // ignore stdin - input fclose($pipes[0]); echo stream_get_contents($pipes[1]); // get stdout - output $output = stream_get_contents($pipes[1]); fclose($pipes[1]); // get stderr - errors $errors = stream_get_contents($pipes[2]); fclose($pipes[2]);}

here $pipes[1] is empty. the process takes around 3 seconds to execute. i guess that is the reason for the problem. I tried running a simple 'echo foo' as cmd and it is running fine. but for this pos tagger command m facing this problem....

i suggest you to run the code in windows to better understand the problem...

mosalski commented 8 years ago

I just encountered a bug related to Utf-8 support in windows system when using proc_open(). This may be related to your issue too.