Solved

system() call hangs

Posted on 2003-11-15
11
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

749 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