Can't get curl working in wamp - php

I'm a complete PHP/wamp noob but am just trying to get a simple bit of code to work. I'm using a library to help me out with OAuth for Twitter, and have been writing and testing my code with wamp on Windows.
This is my code:
<html>
<body>
<?php
include 'tmhOAuth.php';
include 'tmhUtilities.php';
$tweet_text = 'Test Tweet. If you can see this, my PHP code is working! Yay';
echo "Posting...\n";
$result = post_tweet($tweet_text);
echo "Response code: " . $result . "\n";
function post_tweet($tweet_text) {
$connection = new tmhOAuth(array(
'consumer_key' => 'xxxxxxxxxx',
'consumer_secret' => 'xxxxxxxxxxxx',
'user_token' => 'xxxxxxxxxxxxxxxxx',
'user_secret' => 'xxxxxxxxxxxxxx',
));
$connection->request('POST',
$connection->url('1/statuses/update'),
array('status' => $tweet_text));
return $connection->response['code'];
}
?>
</body>
</html>
And the error message I get:
Fatal error: Call to undefined function curl_init() in C:\wamp\www\PHP\tmhOAuth.php on line 581
tmhOAuth is one of the library files I'm using.
After a quick Google, I followed this tutorial:
http://www.phpmind.com/blog/2011/02/how-to-enable-curl-in-wamp/
I found php.ini in both the apache and php folders, and uncommented the lines about curl. I also replaced php_curl.dll in the ext folder with a different version of the file as instructed by another tutorial I found.
Please help

Did you check which php.ini is loaded with your PHP? Make php file and put phpinfo() in it, run it and check for "Loaded configuration file"
Did you restart webserver? Because php.ini is reloaded on webserver restart in Your case.
Is this class using https protocol? Then You need to uncomment openssl extension also.

A good you to test your PHP.INI configuration in windows, is to run the PHP-CLI or check the log.
You can open the cmd and run the command php to see what's going on with your conf.

Related

POST https://kayaindia.in/kaya/sendNotificationB.php 500 (Internal Server Error)

I an creating a PWA app and its working fine, but when I tried to upload on server I stuck on error. On windows local server, everything is fine even notifications, and I dont know much putty/linux commands.
check here my phpinfo file.
I am tring to upload to amazon ec2 server. I installed apache, php, ssl and other required things. And its working file except notifications.
When I call my notification file, I got 503 response. I installed composer, installed everything. I used this github library.
As I understand, I stuck on gmp extension, When I open phpinfo() I didnt see gmp over there. I installed gmp using sudo yum install php-gmp and also I see a file in php.d named as 20-gmp.ini and it included extension=gmp. Also restarted apache server using sudo apachectl stop, sudo apachectl start.
But still I am getting error. And I coudnt see gmp in phpinfo().
notificationb.php
<?php
require __DIR__ . '/vendor/autoload.php';
use Minishlink\WebPush\WebPush;
use Minishlink\WebPush\Subscription;
$subscription = Subscription::create(json_decode(file_get_contents('php://input'), true));
print_r($subscription);
$auth = array(
'VAPID' => array(
'subject' => 'https://github.com/Minishlink/web-push-php-example/',
'publicKey' => file_get_contents(__DIR__ . '/scripts/keys/public_key.txt'), // don't forget that your public key also lives in app.js
'privateKey' => file_get_contents(__DIR__ . '/scripts/keys/private_key.txt'), // in the real world, this would be in a secret file
),
);
$webPush = new WebPush($auth);
$res = $webPush->sendNotification(
$subscription,
"Welcome to Kaya. You can book Appointments and many more."
);
foreach ($webPush->flush() as $report) {
$endpoint = $report->getRequest()->getUri()->__toString();
if ($report->isSuccess()) {
echo "[v] Message sent successfully for subscription {$endpoint}.";
} else {
echo "[x] Message failed to sent for subscription {$endpoint}: {$report->getReason()}";
}
}
?>
If you need any thing, let me know in command. I will update here.
Edit 1: Also I tried to add gmp extension in php.ini in /etc/php.ini but still not added.
I think I am getting error on $subscription = Subscription::create(json_decode(file_get_contents('php://input'), true));
I know I am commenting my own question, As I was searching this answer for 3-4 days I think I should share this info with everyone.
The issue is, In linux, PHP have different-different configuration files. The main configuration file is php.ini. And it include other extensions after loading this file and override mail file. These additional configuration are located in /etc/php.d/ (in my case, which is common for mostly).
So just restarting apache server in not enough. We need to also restart php-fpm.
To restart php-fpm: sudo service php-fpm restart
And then restart apache: sudo apachectn restart
You can check more here
To apply change in php.ini, you need to restart apache server and also restart php.
sudo service php-fpm restart
sudo apachectn restart
Also sometime it took time to apply changes to server.

Error GRPC Spanner Google Cloud With PHP

I'm using PHP to try using the Google Cloud Spanner. I already did the gCloud settings and everything, and that's right. Now I need to make the connection via PHP to do a CRUD with the database that is in Spanner, but the code below always returns the error:
PHP Fatal error: Undefined constant 'Grpc\STATUS_UNKNOWN' in
/xxx/xxxx/www/vendor/google/cloud-spanner/Connection/Grpc.php on line
129
The code I have is:
<?php
require 'vendor/autoload.php';
use Google\Cloud\Spanner\SpannerClient;
/* Error start here */
$spanner = new SpannerClient([
'projectId' => 'my-project-id'
]);
$db = $spanner->connect('instance', 'database');
$userQuery = $db->execute('SELECT * FROM usuario WHERE login = #login', [
'parameters' => [
'login' => 'devteam'
]
]);
$user = $userQuery->rows()->current();
echo 'Hello ' . $user['login'];
The requirements I use in the composer are:
"require": {
"google/cloud": "^0.32.1",
"google/cloud-spanner": "^0.2.2"
}
I noticed that if I enter through the browser, the error presented above continues to appear. If I run the command php teste.php on the terminal, it runs the script correctly, ie, the terminal works and the browser does not.
Google Cloud PHP's spanner client is gRPC only. This means to use it you will need to install the gRPC PHP extension:
pecl install grpc
Once you have done that, add google/proto-client-php and google/gax to your composer.json and run composer update. After this is done, the error will be resolved.
For those wanting more detailed instructions, see this page for installing and enabling gRPC for PHP!
Since you mentioned that it works on CLI but not on browser, I can say that you need to enable the grpc extension on your php web server config.
E.g. Add
extension=grpc.so to your /etc/php/5.6/apache2/php.ini

phpredis errors Class Redis not found in Linux

I met a weied problem when installing phpredis by
cd phpredis && ./configure && make && make install
after that, I add
extension=redis.so
into php.ini.
I can get an OK by running
php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"
BUT when running http:127.0.0.1, nginx throw a error " Fatal error: Class 'Redis' not found in index.php"
<?php>
$client = new Redis();
<?>
I guess this may be some problems related with environment...
Thanks for any advice!
The command line probably does not use the same php.ini file than the web server.
Use phpinfo(); to know which configuration file is loaded in both cases and then declare your extension in the ini file used by your web server.
I had this issue minutes ago, and I solved it restarting the server, this way the server refresh *.ini files
If you're using composer and get the error "Class Redis not found" try put a backslash before the name class. Like this:
<?php
$client = new \Redis();
<?

PHP Error Class 'SoapClient' not found

I was trying to install Wordpress on our server to test, but in order to do that I had to upgrade our current PHP version to 5.3. I upgraded our PHP and I am now finding that our Purolator shipping module is no longer working. According to our host support the "purolator.php" file is missing data that the new version of PHP requires. Unfortunately, I can't revert our PHP version back and our programmer is away.
This is the error message I was able to get from our website host support team:
tail /var/www/vhosts/phantomcables.com/statistics/logs/error_log -f
[Thu Jul 19 08:34:28 2012] [error] [client 70.51.168.201] PHP Fatal
error: Class 'SoapClient' not found in
/var/www/vhosts/phantomcables.com/httpdocs/shippings/purolator.php on line
49, referer: https://phantomcables.com/index.php?dispatch=checkout.cart
These are lines 40 to 72:
function createPWSSOAPClient()
{
/** Purpose : Creates a SOAP Client in Non-WSDL mode with the appropriate authentication and
* header information
**/
//Set the parameters for the Non-WSDL mode SOAP communication with your Development/Production credentials
//echo DIR_SHIPPING_FILES."estimatingservice.wsdl";
$url = "https://webservices.purolator.com/PWS/V1/Estimating/EstimatingService.asmx";
$client = new SoapClient( DIR_SHIPPING_FILES."estimatingservice.wsdl",
array (
'trace' => true,
'location' => $url,
'uri' => "http://purolator.com/pws/datatypes/v1",
'login' => PRODUCTION_KEY,
'password' => PRODUCTION_PASS
)
);
//Define the SOAP Envelope Headers
$headers[] = new SoapHeader ( 'http://purolator.com/pws/datatypes/v1', 'RequestContext',
array (
'Version' => '1.0',
'Language' => 'en',
'GroupID' => 'xxx',
'RequestReference' => 'Rating Example'
)
);
//Apply the SOAP Header to your client
$client->__setSoapHeaders($headers);
return $client;
}
Any help would be greatly appreciated.
It seems like you did not have installed the php-soap package on your server.
Type
phpinfo();
in your code and check if 'Soap Client' is 'enabled'.
If not, I don't know your distribution and package manager, but here is the code for Fedora I use:
$ yum install php-soap
I suggest to do it with your programmer back or a sys admin by your sides, you never know what could happen. A backup is also useful before any installation!
You will need to add (or remove any comment characters before)
extension=soap.so
to your php.ini file, and then restart the web server.
If you are having trouble finding your php.ini file, create a page with the following:
<?php phpinfo();
and load that file in your browser.
On some systems, this setting may not actually live in php.ini. For example, if you are using Zend Server, the setting would live in /usr/local/zend/etc/conf.d/soap.ini.
So we reverted back to an older version of PHP, and re-enabled SOAP. apparently that was the issue, not sure why that didn't work with the newer version of PHP.
Again thank you for all of your help. This is a great community.
It is already posted here
Do the following:
Locate php.ini in your apache bin folder, I.e Apache/bin/php.ini
Remove the ; from the beginning of extension=php_soap.dll
Restart your Apache server
Look up your phpinfo(); again and check if you see a similar picture to the one above
If you do, problem solved!
Enable the SOAP extension, require it in your composer.json like so:
{
"require": {
"ext-soap": "*"
}
}

Embed.ly and PHP... round 2

Apparently my last question was too vague even though it was pretty straightforward.
I'm trying to use Embed.ly's API to embed some stuff, for example, some of the stuff shown here.
https://github.com/embedly/embedly-php/blob/master/README.rst
I have the entire Embedly.php source file in my working directory.
However, when I have the following in my header file:
<?php
//require_once('Embedly/src/Embedly/Embedly.php'); // if using pear
require_once('./Embedly.php'); // if using source
$api = new Embedly\Embedly(array('user_agent' => 'Mozilla/5.0 (compatible; mytestapp/1.0)'));
?>
And the following in my main page:
<?php
$objs = $api->oembed(array(
'urls' => array(
'http://www.youtube.com/watch?v=sPbJ4Z5D-n4&feature=topvideos',
'http://twitpic.com/3yr7hk'
)
));
?>
I get the following error:
( ! ) Fatal error: Call to undefined function Embedly\curl_init() in C:\wamp\www\Embedly.php on line 259
It looks like curl isn't installed or enabled.
If you're on you own server (assuming something similar to ubuntu server), a simple sudo apt-get install php5-curl should solve it.
Otherwise, you may have to contact your hosting provider.
Got this from a forum and it seems legit:
Close WAMP (if running)
Navigate to WAMP\bin\php(your version of php)\
Edit php.ini
Search for curl, uncomment extension=php_curl.dll
Navigate to WAMP\bin\Apache(your version of apache)\bin\
Edit php.ini
Search for curl, uncomment the line/remove the #, extension=php_curl.dll
Save the files
Restart WAMP

Categories