Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7744017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:40:24+00:00 2026-06-01T09:40:24+00:00

I build PHP for android using the NDK. Most functions tested so far run

  • 0

I build PHP for android using the NDK. Most functions tested so far run perfectly, except…

All exec related php function (like exec, shell_exec, popen, ..) all sefgault.

php sample code (test.php)

<?php
$s=shell_exec("ls");
echo $s
?>

result:

# php test.php
[1]   Segmentation fault

I added some debug code to the internal shell_exec function

PHP_FUNCTION(shell_exec)
{
    FILE *in;
    size_t total_readbytes;
    zval **cmd;
    char *ret;
    php_stream *stream;

    if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &cmd)==FAILURE) {
            WRONG_PARAM_COUNT;
    }

    if (PG(safe_mode)) {
            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot execute using backquotes in Safe Mode");
            RETURN_FALSE;
    }

    convert_to_string_ex(cmd);
#ifdef PHP_WIN32
    if ((in=VCWD_POPEN(Z_STRVAL_PP(cmd), "rt"))==NULL) {
#else
    if ((in=VCWD_POPEN(Z_STRVAL_PP(cmd), "r"))==NULL) {
#endif
            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute '%s'", Z_STRVAL_PP(cmd));
            RETURN_FALSE;
    }

    stream = php_stream_fopen_from_pipe(in, "rb");
    total_readbytes = php_stream_copy_to_mem(stream, &ret, PHP_STREAM_COPY_ALL, 0);
    php_stream_close(stream);

    printf("TEST\n%s\n",ret);

    if (total_readbytes > 0) {
            RETURN_STRINGL(ret, total_readbytes, 0);
    } else {
            RETURN_NULL();
    }
}

result

# php test.php
TEST
test.php
[1]   Segmentation fault

I conclude

– the exec of ls is working fine

– the result of the ls is ok

Still something gets wrong.

Question 1:

Can someone point me to the code section where the PHP_FUNCTION(shell_exec) is executed, so i can try to see some more details of where it goes wrong

Question 2:

Any hints on what might be wrong.

Version info

Android 2.3.1

Android NDK 6

PHP 5.2.17

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:40:25+00:00Added an answer on June 1, 2026 at 9:40 am

    Thanx to the anonymous who send me an email with some usefull tips.

    As it turns out php uses popen for al its exec related code.
    A some might know androids bionic version of popen was quite buggy up until ICS and it is know the corrupt the stack.

    I modified php to use a modified verion of popen
    Now php exec/shell_exec etc all run without any problems

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MySQL and PHP to build a data layer for a flash
I'm using the DOM extension in PHP to build some HTML documents, and I
I'm using a combination of PHP and Phonegap. I use PHP to build the
I build a css file using PHP which allows me to easily customize the
I am using PHP and jQuery to build an interactive timeline which needs to
I am trying to build a Connect app using PHP and the Zend Framework.
Hello I know all about http://www.php.net/manual/en/function.http-build-query.php to do this however I have a little
Using Codeigniter, I am trying to get a php script to run after a
i am looking to build a php function which will list all folders and
How can I build a PHP navigation menu that highlights the current page using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.