Jump to content

Script Hangs on pclose()


jorgep

Recommended Posts

Hi guys,

 

I've been three days trying to solve a problem with this script. It is supposed so work as it is, because is running on other machines (Linux and Windows) and is working. FYI I'm using Windows-Apache-PHP-MySQL.

While trying to debug it, it successfully executes the command since I get an answer and is the answer that I'm expecting, but when I try to output something right after the pclose() function, it just hangs there, the memory usage of Apache goes from 22k to 60k or 70k and never get a response.

 

Have anyone ever experienced this before? Please let me know, thanks a lot! I greatly appreciate it!

 

function get_colorspace($file){
$cmd = "identify -format '%r' $file";
$handle = popen($cmd, 'r');
$read = fgets($handle);
pclose($handle);
if (strlen($read)>20){
	$clrname = substr($read, strlen($read)/2);
} else {
	$clrname = $read;
}
$colorspace = ereg_replace("'|DirectClass","",$clrname);
return strtoupper($colorspace);
}

Link to comment
Share on other sites

Nope,

 

In fact, this is a function that is used for an ajax response, for debugging I'm just killing it like

 

$read = fgets($handle);

die(var_export($read,true));

 

It shows me the result that I want from the command, but if I try that after the pclose($handle) it just hangs.

(By hangs I mean that it never returns anything, never get a response and the browser keep thinking)

 

pclose($handle);

//Wont go further

die(var_export($read,true));

Link to comment
Share on other sites

Try this:

 

this will print out the buffer... hopefully.

 

<?php
function get_colorspace($file){
ob_start();
$cmd = "identify -format '%r' $file";
$handle = popen($cmd, 'r');
$read = fgets($handle);
ob_flush();
pclose($handle);
ob_clean();
if (strlen($read)>20){
	$clrname = substr($read, strlen($read)/2);
} else {
	$clrname = $read;
}
$colorspace = ereg_replace("'|DirectClass","",$clrname);
return strtoupper($colorspace);
}
?>

Link to comment
Share on other sites

I tried it, but keep getting the same results. The script just hangs there.

I tried some variations and killing it, and it just don't go after the pclose().

Would you think is a sever configuration problem? Cuz whats weird is the fact that it runs on other servers without problem.

 

:S I have no clue by now.

Link to comment
Share on other sites

Yes, you are right, I tried that yesterday... It still hangs, but is dying there on those functions (popen and pclose).

I also tried executing the command directly on the cmd.exe and it returns the value expected and finishes normally.

Link to comment
Share on other sites

The command that I'm getting is correct, in fact I'm getting the result that I want, If I echo

 

$read = fgets($handle);

echo $read;

 

I will see DirectClassRGB, that is exactly what I want. <- That is, killing the script before the pclose() function.

 

I just tried what you sugested and it dies too... :S. That sort of confirm that is something with my machine :S.

 

I also tried with proc_open and seems to be the same.

>:(

Link to comment
Share on other sites

What does the following produce?

 

<?php
function get_colorspace($file){
  var_export($file);
  $cmd = "identify -format '%r' ".escapeshellcmd($file);
  var_export($cmd);
  $output = $rVal = null;
  exec($cmd, $output, $rVal);
  var_export($output);
  var_export($rVal);
}
?>

Link to comment
Share on other sites

If I'm not wrong, that will hang, as the other script. I'm getting the file correctly, I already verified that.

Yes... I just verified and it hangs... It seems like some weird untrackable error :S.

The server never answer back and keeps waiting for something.

Link to comment
Share on other sites

The identify program is from image ready I think, and it is installed on my machine (the server) and if I die($cmd) and put that directly in the console, that works, in fact in my php script is working too, because I get the result that I want. I tried with hostname as you said and with ipconfig and it just hangs there, returns nothing. I shouldn't be in the php script.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.