jorgep Posted January 24, 2008 Share Posted January 24, 2008 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); } Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/ Share on other sites More sharing options...
The Little Guy Posted January 24, 2008 Share Posted January 24, 2008 do you have any loops near where you are using the function? Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-447855 Share on other sites More sharing options...
jorgep Posted January 24, 2008 Author Share Posted January 24, 2008 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)); Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-447898 Share on other sites More sharing options...
The Little Guy Posted January 24, 2008 Share Posted January 24, 2008 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-447902 Share on other sites More sharing options...
jorgep Posted January 24, 2008 Author Share Posted January 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-447913 Share on other sites More sharing options...
The Little Guy Posted January 24, 2008 Share Posted January 24, 2008 what happens when you comment out pclose($handle); ? by default, if you don't use pclose() PHP will automatically close it. so... if it is still hanging after that is commented out, then it is not the pclose() function that is causing this. Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-447917 Share on other sites More sharing options...
jorgep Posted January 24, 2008 Author Share Posted January 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-447928 Share on other sites More sharing options...
The Little Guy Posted January 24, 2008 Share Posted January 24, 2008 what if... instead you did this: <?php $cmd = "identify -format '%r' $file"; exec($cmd); ?> but... before you do that, comment everything out of the the function, then add this line: echo $file; this will be to make sure that there is actually a value in $file. Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-447941 Share on other sites More sharing options...
jorgep Posted January 24, 2008 Author Share Posted January 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-447970 Share on other sites More sharing options...
jorgep Posted January 24, 2008 Author Share Posted January 24, 2008 :S well thanks to those who tried to help me, I'm still dealing with this. Thank you The Little Guy!. And if anyone knows something or think I can try something, is highly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-448029 Share on other sites More sharing options...
rhodesa Posted January 24, 2008 Share Posted January 24, 2008 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-448041 Share on other sites More sharing options...
jorgep Posted January 24, 2008 Author Share Posted January 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-448052 Share on other sites More sharing options...
rhodesa Posted January 24, 2008 Share Posted January 24, 2008 Wait...you are using Windows you say? Is identify installed on the system? It's not a standard windows program. Try replacing $cmd with something simple like $cmd = "hostname"; Does that work without hanging? Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-448076 Share on other sites More sharing options...
jorgep Posted January 24, 2008 Author Share Posted January 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-448085 Share on other sites More sharing options...
rhodesa Posted January 24, 2008 Share Posted January 24, 2008 you are right...it's definitely something weird. the code here is fine, so the only other tip i have is upgrading PHP Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-448098 Share on other sites More sharing options...
jorgep Posted January 24, 2008 Author Share Posted January 24, 2008 Ok!!! thanks for your help! I dont think I can do that right now, but I'll check to see if it has something to do.! Thanks a gain Quote Link to comment https://forums.phpfreaks.com/topic/87556-script-hangs-on-pclose/#findComment-448139 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.