简体   繁体   中英

PECL OAuth library for PHP - Works in browser, cant compile manually

I am using the PECL OAuth library for PHP which I installed correctly (well, I'm doubting that now). I use it for authentication before querying the LinkedIn API. In my code I create an OAuth object as in the example here , see bottom. It gets the tokens, authorizes the user after he logged in, and successfully fetches data. But the funny thing is that it only works when I run the .php file through my browser (hosted in apache).

When I try to compile the code from the commandline the compiler says: PHP Fatal error: Class 'OAuth' not found in xxx.php on line 15

Obviously I already edited the php.ini to contain the following (or it would not work on the webpage): extension=/usr/lib/php5/20090626/oauth.so

But when I type 'php -m' in the commandline I dont see the oauth module in the list. I have tried getting the filename/location by inserting these lines after making an instance of the OAuth object

$oauthc = new OAuth($oauth['linkedin']['consumerkey'], $oauth['linkedin']['consumersecret'],OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI);
$reflector = new ReflectionClass("OAuth");
$fn = $reflector->getFileName();
echo "[".dirname($fn)."]";

But this only returned the 2 brackets. I have no clue why it apparently works in the browser. Hopefully somebody can help me out.

PHP can use different php.ini config files depending on what SAPI is currently in use. For example, there can be files (depends on linux distribution):

  • /etc/php5/cli/conf.d/*.ini -> loaded when run in CLI mode
  • /etc/php5/apache2/conf.d/*.ini -> loaded when run as an Apache module

So, probably your module is getting loaded when PHP runs as an Apache module, and not loaded for CLI

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM