Solved

system() call hangs

Posted on 2003-11-15
11
259 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Best database setup for image uploads 6 40
Time difference 10 35
regex expression 9 23
Tracking Bouncebacks in PHPMailer 3 10
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now