php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73826 Errors with running embeded php on OS X (resolved partially with hacks)
Submitted: 2016-12-28 04:22 UTC Modified: 2017-01-11 05:34 UTC
From: ejrx7753 at gmail dot com Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 7.1.0 OS: OS X 10.12
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ejrx7753 at gmail dot com
New email:
PHP Version: OS:

 

 [2016-12-28 04:22 UTC] ejrx7753 at gmail dot com
Description:
------------
I ported some code from (https://github.com/facebookarchive/phpembed) to PHP 7. At least the init and function call parts. It works on Windows, but on OS X it crashes.

I have done a number of hacks that have gotten it to work on OS X, but am much confused about why it works that way. Actually, on review, it does not offer the same functionality. So I need either a proper init sequence for the embed module, or we have a crash. I can test any suggested updates and put together a test script.

From (https://github.com/facebookarchive/phpembed/blob/master/src/php_cxx.cpp) basic sequence of events:

----init_global_php----

#ifdef ZTS
  // PHPE: if they want threads, let's give them more than 1!
  tsrm_startup(128, 32, 0, NULL);
  compiler_globals = (zend_compiler_globals *)ts_resource(compiler_globals_id);
  executor_globals = (zend_executor_globals *)ts_resource(executor_globals_id);
  core_globals = (php_core_globals *)ts_resource(core_globals_id);
  sapi_globals = (sapi_globals_struct *)ts_resource(sapi_globals_id);
  tsrm_ls = (void ***)ts_resource(0);
#endif

  sapi_startup(&php_embed_module);

  if (php_embed_module.startup(&php_embed_module)==FAILURE) {
    return FAILURE;
  }

  zend_llist_init(&global_vars, sizeof(char *), NULL, 0);


///// Code fails with segmentation fault inside one of the ts_resource calls ////




//// Working Code on OS X ///////////

    tsrm_startup(2, 32, 0, NULL);
    
    int argc = 1;
    char* text = copy_literal("embed4");
    char *argv[2] = { text, NULL };
    php_embed_init(argc, argv);



/////////////////////////////////////


This working code I pulled from someone's git repo, and it contained the comment "////What is this? I pulled it from a textbook. Don't know what it does".


So this generates three questions
1. Should the code above that works on Windows work on Mac OS X?... If there is a bug.
2. What is the proper init sequence (if code #1 is a little big "off")?
3. Should there not be unit tests for php embed sapi? To what extent is debateable, but at least the startup/function call/parse script/run script/shutdown aspects.

I can make a reproducable case for this bug, but want to verify #2 before doing so.

Test script:
---------------
Will post when verified proper usage and tested it.

Expected result:
----------------
working code, as on Windows

Actual result:
--------------
Segfault inside ts_resource somewhere, and various other places depending on how code is commented/ordered.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-11 05:34 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2017-01-11 05:34 UTC] krakjoe@php.net
The code you have linked too is not supported by PHP, or the authors (facebook).

Having tested the embed SAPI this morning in ZTS and non-zts, I can say with confidence there are no problems in php-src, and any bugs you are experiencing are because of mistakes in your attempt to port that old (PHP5) code.

Sorry, but there is nothing we can do to help you, other than to suggest that you use the embed SAPI directly.
 [2017-01-11 13:59 UTC] ejrx7753 at gmail dot com
Hi,

Did you test the embed SAPI on OS X? If so can you post the code that you used for those tests? I know that this code works on Windows, for example, after porting, so it os OS-specific, and I would be glad to get a link to better code to use as an example.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC