Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

system() call hangs

Posted on 2003-11-15
11
Medium Priority
?
270 Views
Last Modified: 2009-07-29
In a PHP program(php1.php) i have a system() call like this:

system('/usr/local/bin/sh php2.php arg1');

The original PHP program (php1.php) when executed hangs. It stops responding. But if the system call is commented the program works fine.

The second PHP file (php2.php) when executed from the command line works fine. But when the same php2.php is called from the php1.php using the system() the code stops responding.

What might be the reason?

Thanks,
Navanee
0
Comment
Question by:rnavanee
11 Comments
 
LVL 14

Expert Comment

by:ThG
ID: 9753800

What you are doing is basically wrong.
What is '/usr/local/bin/sh'? a bash compiled yourself?
Do this command work if typed in the command line?
 $ /usr/local/bin/sh php2.php arg1

Even if it works, what you typed above means:
/bin/sh -c '/usr/local/bin/sh php2.php arg1'
which makes no sense.

What you probably want is this:
system("/usr/local/bin/php -f php2.php arg1");

Let me know if my considerations are correct :-)
0
 

Author Comment

by:rnavanee
ID: 9753858
Sorry I made a mistake ...

The call is ..
system('/usr/local/bin/php php2.php arg1');

This call makes causes the execution to hang.

I tried using 'php -f';  Even this fails...


Thanks,
Navanee


0
 
LVL 14

Expert Comment

by:ThG
ID: 9753966
and what happens from the command line?
 $ php -f php2.php arg1

note that without the -f it's normal that it hangs, because it tries to read from standard input something that will never arrive
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:aolXFT
ID: 9759945
system('/usr/local/bin/php php2.php arg1');

hmmm

Do you have shell access to the machine that this is running on? If so, then try executing the command on the command line.

Does it hang?

Try

system('/usr/local/bin/php php2.php arg1 &');

If this does work it will be a temperary fix. you'll need to fix the command so that it doesn't hang.

You might also make sure that /usr/local/bin/php is the correct path.

Why are you trying to do this? There's usually a better way to do things than using system(). You also lose the advantages of running the system as a module(if you are doing so).
0
 

Author Comment

by:rnavanee
ID: 9762701
The call was

...
system ('/usr/local/bin/php $scriptName $arg');
...

The Single quote (') is the cause for all the problems...

I found it by myself.

Thanks
0
 
LVL 14

Expert Comment

by:ThG
ID: 9762896
Sure it was, but another time please ask the question as it is in reality.
0
 

Author Comment

by:rnavanee
ID: 9762946
Yes. I agree. It was my mistake. Sorry for that.
0
 
LVL 9

Expert Comment

by:techtonik
ID: 12198529
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12573094
PAQed with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question