PHP fatal error on creating Com Object - php

I have a php web application that needs to access a PI-Datasource using an application-library written for windows on dll form to fetch the data. Due to the non-polimorphism of PHP we are using a wrapper written in C#-Dotnet in order to use the polimorphism library.
PHP->Wrapper->Lib->PI-System
The problem: PHP crashes, without leaving a log, on the creation of the com object (almost always on every second request). My thought was that probably something in the existing php code could be wrong that causes this fatal-error and after a lot of debugging and trying I simplified the code to this:
$connection = new Com('Something.SomethingClass');
with the variable $connection not being used NEVER! and still every 2nd time I get php-crash (documented in windows error log with an 1000-Error and an 1001-Information)
>Faulting application name: php-cgi.exe, version: 5.4.11.0, time stamp: 0x511a30ec
>Faulting module name: KERNELBASE.dll, version: 6.1.7601.17932, time stamp: 0x503275ba
>Exception code: 0xc0000005
>Fault offset: 0x0000d3cf
>Faulting process id: 0x14d0
>Faulting application start time: 0x01ce89dd0ae23748
>Faulting application path: C:\Program Files\Zend\ZendServer\bin\php-cgi.exe
>Faulting module path: C:\Windows\system32\KERNELBASE.dll
So i tried to generate even more com objects..
$connArray = array();
for($i = 0; $i < 50 ; $i++){
Core_System_Log::getInstance()->logWithoutMessageId('Before: ' . $i ,Core_System_Log::DEBUG);
$connArray[i] = new Com('Something.SomethingClass');
Core_System_Log::getInstance()->logWithoutMessageId('After: ' . $i, Core_System_Log::DEBUG);
}
All 50 were generated with no problem, and again every 2nd time i tried i got a php fatal error.
I tried to used all 50 of them, and they all read values from the PI-System with no problem.
I tried to unset the variables and call also the gc, call the destructor from C#, check the constructor from C# (which just makes an object of the library and had no exception, the object was normally created and still php crashed) but the problem did not disappear.
So, is there any idea? am i doing something wrong (how can it be wrong when every 2nd time it is properly reading the values)?
Environments Tested:
OS:Windows Server 2008 R2 64Bit / Windows 7 Prof SP1 32/64Bit
PHP: 5.3.9/ 5.3.14 / 5.3.21 / 5.4.11
WS: Apache and IIS (few different versions)
UPDATE: The problem was finally in the C# code. There was a call to GC which did not allow the COM object to be closed/deleted correctly having as a result C# to hang (again with no exception) and "triggering" the php fatal error.
Thanks for the responses.

If returns crashed without logging into file it look that in code contains sign #.
Example:
#some_function()
This will call function, but if has any errors it will not showing to you, just skipping. Due to some errors PHP can be stopped.
But, can you try upgrade PHP to 5.5 on Windows server?
If you know in which of lines of code throws an error and want to skip, just put isset()
If isset($somevar) or isset(function()) returns true that means are not errors, but if you don't want to stop a function on errors put isset() on a line of code where errors occurred.
I'm not sure how looks class and function inside PHP->Wrapper->Lib->PI-System code so I can tell fully corrected answer.

UPDATE: The problem was finally in the C# code. There was a call to GC which did not allow the COM object to be closed/deleted correctly having as a result C# to hang. The object was somewhere kept in Ram and the second time the wrapper was called it just hanged/exited (again with no exception) which "triggered" the php fatal error.

Related

Problems using SAPI with PHP through COM, on IIS

I am attempting to get Text To Speech and Speech Recognition to work in PHP using Microsoft's SAPI through COM objects.
In the past, I already used this code to get TTS to work (Apache 2.1, PHP 5.5, on Windows 2003 Server)
// Instantiate the object
$VoiceObj = new COM("SAPI.SpVoice") or die("Unable to instantiate SAPI");
// Get the available voices
$VoicesToken=$VoiceObj->GetVoices();
$NumberofVoices=$VoicesToken->Count;
for($i=0;$i<$NumberofVoices;$i++)
{
$VoiceToken=$VoicesToken->Item($i);
$VoiceName[$i]=$VoiceToken->GetDescription();
}
// Get and print the id of the specified voice
$SelectedVoiceToken=$VoicesToken->Item(0);
$SelectedVoiceTokenid=$SelectedVoiceToken->id;
// Set the Voice
$VoiceObj->Voice=$SelectedVoiceToken;
$VoiceName=$VoiceObj->Voice->GetDescription();
$VoiceFile = new COM("SAPI.SpFileStream");
$VoiceFile->Open('./test.wav', 3, false);
// Speak to file
$VoiceObj->AudioOutputStream = $VoiceFile;
$VoiceObj->Speak("What an unbelievable test", 0);
$VoiceFile->Close();
On my new setup (IIS 7.5, PHP 7.0, Windows Server 2008R2) the same code fails at
$VoiceObj->Speak("What an unbelievable test", 0);
Fatal error: Uncaught com_exception: <b>Source:</b> Unknown<br/><b>Description:</b> Unknown in \\web\tts.php:30 Stack trace: #0 \\web\tts.php(30): com->Speak('this is a marve...', 0) #1 {main}
With such little detail (where to retrieve more?) I can't figure out what the problem may be.
Writing permissions checked.
PHP 7.0 replaced with 5.5, still not working.
Same code tested with a Win32 app, and it works flawlessly.
Any hints?
Two years later, I casually happen to find an answer to this problem.
PHP COM Objects can't perform file operations on network paths, even with all the required permissions
Once the development folders were moved on the same machine where IIS runs, a bunch of previously broken tests started working. They all had one thing in common: they were using COM interfaces to save files or something like that.

PHP in TOMCAT 6 - Exception

I have been trying to integrate PHP in APACHE TOMCAT 6 by following second answer for the QUESTION RUN PHP APP IN TOMCAT 6. I am facing troubles with the configuration.
First I got Exception java.lang.UnsatisfiedLinkError: no php5srvlt in java.library.path. which I resolved by placing php5srvlt.jar, generated in step 12, in tomcat\lib.
After that I am facing
java.lang.UnsatisfiedLinkError: net.php.servlet.send(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Z)V
net.php.servlet.send(Native Method)
net.php.servlet.service(servlet.java:190)
net.php.servlet.service(servlet.java:214)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
Exception.
I tried to find solutions for this but could only get close to this QUESTION. But, I do not want to do the whole thing once again, because I have tried several times. I tried with TOMCAT 8.0.15, but failed. Now, just to go in sink with the instructions I have installed TOMCAT 6 and trying to integrate PHP.
I am placing log file for the request made for tomcat/webapps/PHP/test.php.
LOCALHOST.YYYY-MM-DD.log
Dec 29, 2014 12:15:46 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet php threw exception
java.lang.UnsatisfiedLinkError: net.php.servlet.send(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;Z)V
at net.php.servlet.send(Native Method)
at net.php.servlet.service(servlet.java:190)
at net.php.servlet.service(servlet.java:214)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1778)
at java.lang.Thread.run(Thread.java:744)
TEST.PHP
<?php
echo "HELLO WORLD";
?>
EDIT
I mistook that I was getting problem 1 because i did not have php5srvlt.jar in tomcat/lib. But, in fact, problem 1 appears when i request the page for the first time after starting the server. and later on I see problem 2.
I've learned from here that php and pecl version must be same, but still I get the same error even after working with same version numbers 5.2.5
The error message indicates that you're missing .dll-files necessary for such a .. fragile contraption.
The UnsatisfiedLinkError is thrown when an application attempts to load a native library like .so in Linux, .dll on Windows or .dylib in Mac and that library does not exist.
But please - reconsider what you're actually doing. There is (almost) no good reason for running a PHP context inside Tomcat.

Proxy is empty after initializing successfully

I'm using the PECL D-Bus extension with PHP 5.5 on Ubuntu 14.04 to interract with Clementine.
As for now I'm able to connect to the session bus (exceptions are throwns when any error occurs), but when I initialize the proxy object I get an empty DbusObject, so I'm unable to call the D-Bus methods.
Here is the code I use (inspired from the extension usage examples) :
$dbus = new Dbus(Dbus::BUS_SESSION);
$clementine_player_proxy = $dbus->createProxy('org.mpris.clementine', '/Player', 'org.freedesktop.MediaPlayer');
var_dump($clementine_player_proxy); // returns "object(DbusObject)#3 (0) {}"
Of course I checked with d-feet if the bus name, the object path and the interface exists :
I'm stuck for two days.
Edit : submitted bug on the PHP bugreport.
Edit 2 : tested with another method (Addtrack(string, bool)) with another object path (/TrackList). It works. I don't understand.
I ended up to learn Python to properly use D-Bus with ease via the dbus module (as said in the Clementine's wiki).
I recommend to everyone who wants to use the PHP D-Bus extension to not do so : it is buggy, tricky and it has no documentation (except example scripts).

Codeigniter Command line error - PHP Fatal error: Class 'CI_Controller' not found

After following the user guide instructions found here: http://ellislab.com/codeigniter/user-guide/general/cli.html I'm unable to run the test script via command line.
My controller located at /var/www/mysite/application/controllers/
class Tools extends CI_Controller {
public function message($to = 'World')
{
echo "Hello {$to}!".PHP_EOL;
}
}
In my browser I can access
http://mysite/tools/message/ben
And the function correctly outputs "Hello ben"
From terminal I should be able to run:
$ php index.php tools message "Ben"
My terminal should print: "Hello Ben"
However I get the following error:
PHP Fatal error: Class 'CI_Controller' not found in /var/www/mysite/system/core/CodeIgniter.php on line 233
My server is pretty standard; ubuntu LAMP. Codeigniter is pretty standard too and I have no problem running non CI scripts via command line
My PHP binary is only located in /usr/bin/php <-- This post suggests an issue running CI directly from usr/bin/php, however I'm not operating a shared PHP service, and I don't see why this would make a difference to how PHP executes a CI script.
Any help or just an indication on how to debug this would be greatly appreciated.
Thanks in advance.
Solved! (partly) the issue was CodeIgniters error logging.
In application/config/config.php, I modified the following config property:
$config['log_threshold'] = 0;
This disables logging, and allows $ php index.php to execute.
If anyone can explain why CI only shows this error on CLI PHP - might help anyone else who has this issue and needs it resolved with error logging on.
To solve error "Class 'CI_Controller' not found" try going to Application -> Config -> database.php then check the database details like hostname, username, password and database.
To Mijahn:
I had this same problem, and after about two hours of tracing through code to figure out the problem, it seems that there is some sort of conflict with loading the CI_Controller when utilizing the native PHP load_class function.
I worked around this issue by making the following changes to the Common.php file (hack, I know).
//$_log =& load_class('Log');
require_once('system/libraries/Log.php');
$_log = new CI_Log();
My logs then where created exactly like I wanted. Hope this hack helps.
This site says to run codeigniter from the command line, one must set the $_SERVER['PATH_INFO'] variable.
$_SERVER['PATH_INFO'] is usually supplied by php when a web request is made. However, since we are calling this script from the command line, we need to emulate this small part of the environment as a web request.
The answer provided in this Stack Overflow post worked for me.
Within system/core/CodeIgniter.php, on around line 75, change:
set_error_handler('_exception_handler');
to...
set_exception_handler('_exception_handler');
Other users have reported that this gave them a better backtrace with which to debug the underlying issue, but for me, this actually removed the problem altogether.

PHPUnit Segmentation fault

When a PHPUnit test fails normally on my dev box (Linux Mint), it causes a "Segmentation Fault" on my Continous Integration box (Centos). Both machines are running the same version of PHPUnit. My dev box is running PHP 5.3.2-1ubuntu4.9, and the CI is PHP 5.2.17. I'd rather leave upgrading the PHP as a last resort though.
As per this thread: PHPUnit gets segmentation fault
I have tried deactivating / reinstalling Xdebug. I don't have inclue.so installed.
On the CI box I currently only have two extensions active: dom from php-xml (required for phpunit) and memcache (required by my framework), all the others have been turned off.
Next to what cweiske suggests, if upgrading PHP is not an option for you and you have problems to locate the source of the segfault, you can use a debugger to find out more.
You can launch gdb this way to debug a PHPUnit session:
gdb --args php /usr/bin/phpunit quiz_service_Test.php
Then type in r to run the program and/or set environment variables first.
set env MALLOC_CHECK_=3
r
You might also consider to install the debugging symbols for PHP on the system to get better results for debugging. gdb checks this on startup for you and leaves a notice how you can do so.
I've had an issue with PHPUnit segfaulting and had trouble finding an answer, so hopefully this helps someone with the same issue later.
PHPUnit was segfaulting, but only:
If there was an error (or more than one)
After all tests had run but before the errors were printed
After a while I realized that it was due to failures on tests that used data providers, and specifically for data providers that passed objects with lots of recursive references. A bell finally went off and I did some digging: the problem is that when you're using data providers and a test fails, PHPUnit tries to create a string representation of the provided arguments for the failure description to tell you what failed, but this is problematic when one of the arguments has some infinite recursion. In fact, what PHPUnit does in PHPUnit_Framework_TestCase::dataToString() (around line 1612) is print out all the arguments provided by the data provider using print_r, which causes the segfault when PHP tries to create a string representation of the infinitely recursive object.
The solution I came to was:
Use a single base class for all my test classes (which fortunately I was already doing)
Override dataToString() in my test base class, to check for these kinds of objects in the data array (which is possible in my case because I know what these objects look like). If the object is present, I return some special value, if not I just pass it along to the parent method.
I had similar problem and by disabling the garbge collactor in
PHPStorm => Edit configuration => Interpreter option : -d
zend.enable_gc=0
Or if you are running your tests from the command line you may try adding :
-d zend.enable_gc=0
When you get a segfault, upgrade your PHP to the latest version. Not only the latest in your package manager, but the latest available on php.net. If it still segfaults, you are sure that the problem has not been fixed yet in PHP itself. Don't bother trying to get rid of a segfault in old version of PHP because it might have been fixed already in a newer one.
Next step is to locating the problem: Make your test smaller and smaller until you can't remove anything (but it still segfaults). If you have that, move the test into a standalone php script that segfaults. Now you have a test script for your bug in the PHP bug tracker.
In addition to https://stackoverflow.com/a/38789046/246790 which helped me a lot:
You can use PHP function gc_disable();
I have placed it in my PHPUnit bootstrap code as well with ini_set('memory_limit', -1);
I had the same problem and could nail it down, that I tried to write a class variable which was not definied:
My class (it's a cakePHP-class) which caused segmentation fault:
class MyClass extends AppModel {
protected $classVariableOne;
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->classVariableOne =& ClassRegistry::init('ClassVariableOne');
// This line caused the segmentation fault as the variable doesn't exists
$this->classVariableTwo =& ClassRegistry::init('ClassVariableTwo');
}
}
I fixed it by adding the second variable:
class MyClass extends AppModel {
protected $classVariableOne;
protected $classVariableTwo; // Added this line
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->classVariableOne =& ClassRegistry::init('ClassVariableOne');
$this->classVariableTwo =& ClassRegistry::init('ClassVariableTwo');
}
}
Infinite recursion is normally what causes this issue for us. The symptoms of infinite recursion seem to be different when running code under phpunit, than they are when running it in other environments.
If anyone comes across this in relation to PHPunit within Laravel
It took a while to figure out what the issue was. I was going over the differences between my current code and the previous revision and through some trial and error finally got there.
I had two different models that were both including each other with the protected $with override.
This must have been causing some kind of loop that phpunit could not deal with.
Hopefully someone finds this useful.
Please update to the newest XDEBUG. Got the same error while using v3.1.5, and after upgrading to 3.1.6 eveything works.
I got into the same problem. I upgraded the PHPUnit to the 4.1 version (to run the tests) and it was able to show me the object, as pointed by Isaac.
So, if you get to this very same problem, upgrade to PHPUnit >= 4.1 and you'll be able to see the error instead of getting "Segmentation fault" message.
I kept getting a Segmentation fault: 11 when running PHPUnit with Code coverage. After doing a stack trace of the segmentation fault, I found the following was causing the Segmentation fault error:
Program received signal SIGSEGV, Segmentation fault.
0x0000000100b8421a in xdebug_path_info_get_path_for_level () from /usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
I replaced my current xdebug.so in the path above with the latest version from the Komodo Remote Debugging Package the sub-folder of the corresponding downloaded package with the PHP version I have (which is 5.5 for me) and everything worked.
The following fixed a similar issue for me (when the output of the gdb backtrace included libcurl.so and libcrypto.so):
disable /etc/php.d/pgsql.ini:
; Enable pgsql extension module
; extension=pgsql.so
edit /etc/php.d/curl.ini to ensure that pgsql.so is included before curl:
; Enable curl extension module
extension=pgsql.so
extension=curl.so
curl.cainfo=/home/statcounter/include/config/cacert.pem
if you have an object with property pointing to the same object, or other sort of pointer loops, you will have this message while running
serialize($object);
And if you are a Laravel user, and you are dealing with models. And if you think, you will never have this problem, because you avoiding pointer loops by using $hidden property on your models, please be advised, the $hidden property does not affect serialize, it only affects casting to JSON and array.
I had this problem, when I had a model saved into a property of a Mailable object.
fixed with
$this->model->refresh();
in a __construct method , just before the whole object is serialized.
This related to code not extension. In my case i had these two files
Test Case
Example Test
In Test Case there is method called createApplication. Just leave it empty.
In Example Test you can create the method and fill with
$this->assertTrue(true)
Above is basic setup hope you can extend the requirement as you need.

Categories