PHP and COM Interop assembly (written in C#) RRS feed

  • Question

  • User-840525014 posted

    Hi folks, I've got a weird situation here.

    I've written a C# COM Intertop assembly which is being accessed from PHP website running under IIS 7.5 over Fast CGI on 2008 R2.

    I am seeing unexpected churn within my assembly, with global singleton classes that should only be created once being released and recreated.

    At first I thought this was due to worker process recycling, and part of it in fact was due to this due to the IdleTimeout.  However, now that this has been fixed, I am still seeing these singletons being released and recreated even though the WP is not recycling  It is almost as if the AppDomain within the WP is being released and recreated.

    Since this is a PHP appication, thjere is no way for it to hold a durable reference to any of the COM components across page loads.  So what I do is I have created an "access" class and I create an instance of that class every page load, and call a method which returns the existing Singleton instance (creating it the first time naturally).  Please note that the singleton is free-threaded, so there are no performance issues here.  I actually want all of the requests be running in separate threads against the same class instance.

    However, I'm seeing no errors in my logs, and as I said the WP isn't crashing (the PID never changes).  I've set the IdleTimeout high (1 day), and have also set the ActiveTimeout very high as well.  I have no idea why this is happening.

    When the same DLL is used from ASP.Net, thsi never happens.  Of course, when used from ASP.Net, it is not going through COM Interop.

    If anybody has any ideas I'd love to hear it.

    Monday, December 16, 2013 5:41 PM


  • User690216013 posted

    If you carefully read Fast CGI specs, you will see that even when application pool recycle is disabled, Fast CGI mechanism will recycle PHP processes (php-cgi.exe). Thus, your assembly in turn will be freed and reloaded. It is not weird but by design.

    A better way to interoperate, is to build a web service in C# where you can make your class fully singleton, and then invoke the service on PHP side.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, December 16, 2013 9:58 PM