Fatal error: Class 'COM' not found PHP. Win7 - Apache - PHP - php

$myapp = new COM("word.application");
// returns a fatal error: "Class 'COM' not found in c:/www/comConnector.php"
shell_exec("whoami");
//returns "NT authority/system"
My system setup
Win7 Pro
Apache Server version: Apache/2.2.23 (Win32)
PHP
PHP 5.3.16 (cli) (built: Aug 15 2012 20:06:57)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

Add COM support in php.ini:
[COM_DOT_NET]
extension=php_com_dotnet.dll

Since you are using PHP 5.3.16, make sure that you are pointing to the global namespace:
$myapp = new \COM("word.application");
Even though your PHP file might be in global namespace already, but it's a good practice.

Related

MySQLi reported missing, only in console

I'm using XAMPP and PHP CLI to test my PHP script locally. The problematic line (the line 98) in db.php is:
$this->mysqli = new mysqli($host, $user, $pass, $dbname, $port);
And the error is:
No such file or directory in /path/to/my/file/db.php on line 98
This problem only appears when I execute a PHP file that requires db.php in Terminal. It works fine when I run it in browser. How come?
The CLI command I use is:
php test.php
Well, that's a very simple command. Is there anything I missed?
Note: I'm using Mac OS X 10.10.1
PHP version:
PHP 5.5.14 (cli) (built: Sep 9 2014 19:09:25)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

http.so loaded but http_get undefined

I have LAMP installed on my linux distribution:
///
PHP 5.4.9-4ubuntu2.4 (cli) (built: Dec 12 2013 04:29:20)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
///
In order to use http_get from pecl_http php extension I have explicitly installed it and added the http.so extension to php.ini.
Now I am in the following scenario. Using the simple php code below:
echo var_dump(extension_loaded("http"));
echo var_dump(extension_loaded("raphf"));
echo var_dump(extension_loaded("propro"));
echo var_dump(function_exists("http_get"));
$response = http_get("www.google.com");
echo $response;
I got the following results:
///
boolean true
boolean true
boolean true
**boolean false**
I am not sure why extension_loaded("http") returns true but function_exists("http_get") returns false, so I cannot use the function http_get without getting the following in the Apache log file
"[Tue Dec 31 12:32:26 2013] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined function http_get() in /home/user/main.php on line 32"
Could you please help me troubleshooting this?
(same issue using the console interactive mode php -a)
phpinfo() shows:
///
http
HTTP Support enabled
Extension Version 2.0.3
Used Library Compiled Linked
libz 1.2.7 1.2.7
libcurl 7.29.0 7.29.0
libevent disabled disabled
Directive Local Value Master Value
http.etag.mode crc32b crc32b
///
Thanks
As Michael Berkowski says, the 2.x branch is totally new and it works with a different API.
You can go with the 1.x branch and use the old functions this way:
pecl uninstal pecl_http
pecl install pecl_http-1.7.6
Then you can use http_get
Anyway, if this is a fresh new project, it is recommended to go with the newest API.
Just to elaborate slightly on Alex's answer, unless I missed something, the Php Manuel doesn't really reflect how this extension has changed. And the link in the comment on your question doesn't seem to work anymore. I think what you want now, to get that same behavior, is http\Client::send().

Is there a PHP setting that sets whether you can index the result of a function?

I have two servers. They are both running php 5.3.3. This code works on one server and returns a syntax error on the other. Is there a php ini setting that affects this behaviour? I can't find anything related in the PHP documentation, but I may be looking in the wrong place.
Server 1
> php -v
PHP 5.3.3 (cli) (built: Sep 23 2010 14:15:16)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.0.3, Copyright (c) 2002-2007, by Derick Rethans
php > echo explode(" ", " foo ")[1];
foo
Server 2
> php -v
PHP 5.3.3 (cli) (built: Jan 31 2011 15:57:29)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
php > echo explode(" ", " foo ")[1];
Parse error: syntax error, unexpected '[', expecting ',' or ';' in php shell code on line 1
Another idea: PHP on both servers is custom-compiled, so it could also be a different compile flag.
No.
PHP doesn't support this syntax. It's on the trunk, but not yet released (as of PHP 5.3.3).
I have no idea how it's working on your first server, but perhaps this "Xdebug" is making a difference?
Aha! I figured it out.
We installed Facebook's XHP to profile our development server. This syntax (which is quite elegant) was added in in the PHP module. Here's a diff of the php.ini file between server 1 and 2:
> ; XHP https://github.com/facebook/xhp/wiki/Building-XHP
> extension=xhp.so
> ; adds support for the [] operator on the return value of a function
> xhp.idx_expr = 1
> ; Tracking errors in XHP applications is very difficult without annotations.
> xhp.include_debug = 1
I like this syntax, so I'll probably install XHP on the other server. Thanks for the help Michas for suggesting I diff the ini files.

Segmentation Fault error in PHP, using SOAP to connect to SalesForce

I'm integrating my software (PHP) with SalesForce, using the SalesForce PHP Toolkit.
So far, everything's worked great, but when I started writing the code to call convertLead(), I got a "Segmentation Fault" error.
This is the code I'm running:
require_once('../salesforce/SforceEnterpriseClient.php');
ini_set('soap.wsdl_cache_enabled', 0);
$SForce = new SforceEnterpriseClient();
$result = $SForce->createConnection('../salesforce/enterprise.wsdl.xml');
$result = $SForce->login('user', 'pass+token');
echo "Logged In!";
$data = array(
'convertedStatus' => 'Converted',
'leadId' => '00QC000000mDcmJMAS'
);
$result = $SForce->convertLead(array($data));
That's it. And i'm getting a Segmentation Fault. I tried using StdClass instead of a keyed array, same thing. The convertLead method in the SF toolkit is really simple, it just calls the same method into a SoapClient instance...
NOTE: I'm running this script from the CLI, not through Apache.
UPDATE: Just tried running "strace" with my script. The last lines of it are:
close(4) = 0
write(1, "Logged IN!", 10Logged IN!) = 10
open("error_log", O_WRONLY|O_CREAT|O_APPEND, 0644) = 4
--- SIGSEGV (Segmentation fault) # 0 (0) ---
+++ killed by SIGSEGV +++
Also, in case it's relevant:
php --version
PHP 5.2.13 (cli) (built: Jul 17 2010 22:01:13)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
with the ionCube PHP Loader v3.3.20, Copyright (c) 2002-2010, by ionCube Ltd., and
with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
This also happens in my dev machine (Windows), so I doubt it's the Accelerators or anything like that:
php --version
PHP 5.2.13 (cli) (built: Feb 24 2010 14:37:44)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
This may or may not be specific to SalesForce. Probably not, seems like a bug in the SOAP PHP library. Maybe the request/response are broken, but I can't see those because they're HTTPS.
Any ideas how I can go about diagnosing (or more importantly, working around) this issue?
Thank!
Daniel
There is a bug (still after 4 years) in the PHP soap extension. It has to do with how it handles WSDL caching. Disabling caching with ini_set() does not work. You also need to turn off caching for your particular client instance.
return new SforceEnterpriseClient('../salesforce/enterprise.wsdl.xml', array(
'cache_wsdl' => WSDL_CACHE_NONE
));
This is true even when using the native PHP SoapClient class.
Ok, this doesn't solve the underlying issue, but, in case someone got this same problem with SalesForce and PHP...
Despite what the documentation implies, fields SendNotificationEmail and OverwriteLeadSource ARE MANDATORY, you MUST specify them in the call.
Not doing so should give you a nice error, not a SegFault, but still, that solves it.

strange behaviour of php session

im using php a server, that uses ubuntu 8.04 :
PHP 5.2.4-2ubuntu5.12 with Suhosin-Patch 0.9.6.2 (cli) (built: Sep 20 2010 13:33:05)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
i found a strange behaviour:
<?php
session_name('session');
session_start();
$_SESSION['username']='realName';
$username='otherName';
?>
this leads to, that php saves in the session variable 'otherName' (instead of 'realName'). why is php saving the $username into the session variables? How can i disable this?
thanks in advance for any help... :)
It looks like you have register_globals = on in your php.ini. This option has been deprecated as of PHP 5.3 and you should turn it off. More information can be found here: http://www.php.net/manual/en/security.globals.php

Categories