3

Hi I have a shell script which should run based on the return of php code:

x=1
while [[ "$x" != 5 ]] 
do
  echo "Welcome $x"
  php test.php
  x=$?
done

And the php code

echo "Testdfdf test".PHP_EOL;
exit(4);

So I want whenever I get 5 from php to quit the loop.

But I get sometimes:

./myshell: line 7: 20529 Segmentation fault      php test.php

Should it loop without problem?

1
  • 1
    Enable core dumps with ulimit; run the script; when you look at the core file, it will tell you which process resulted in its creation -- most likely the PHP interpreter, making this not a bash problem; you can then generate a stack trace from the core dump to report to the relevant party. Commented Jul 24, 2009 at 12:12

3 Answers 3

2

Probably because of this error which affects both Ubuntu and Debian... https://bugs.launchpad.net/ubuntu/+source/php5/+bug/343870

Sign up to request clarification or add additional context in comments.

1 Comment

I have the same issue with Debian but not in CentOS
1

It should and it does, but no clue about why php is ending with a segfault.

Comments

1

your shell while loop will loop forever, as your php script returns 4 to shell, and your while loop checks for !=5. which means the condition is not going to be met. what actually is it you are wanting to do? unless necessary, i would advise to do everything with php (or shell) , but try not to intermingle both.

1 Comment

Intermingling both is fully in line with the UNIX ideology of "many small tools"; calling other programs and checking their exit code is, after all, what shell does best. :) The advantage of pushing everything into PHP is that there wouldn't be a need to start up a new interpreter every cycle of the loop -- certainly a performance enhancement, albeit perhaps one with an impact on correctness (if the PHP [ab]uses global variables).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.