I should change sphinxapi.php , my sphinxapi.php on (usr/local/sphinx/lib/sphinxapi.php) i changed it but what should i do after that to use new functions ?
my php :
<?php
$sphinx = new SphinxClient();
$sphinx->SetServer($this->config->sphinx->host, $this->config->sphinx->port);
$sphinx->SetMatchMode(SPH_MATCH_ALL);
$sphinx->SetLimits(0, 1,1);
..filters...
$sphinx->RemoveFilter($color['id']);
My new function :
function RemoveFilter ( $attribute )
{
assert ( is_string($attribute) );
foreach($this->_filters AS $key => $filter){
if($filter['attr'] == $attribute){
unset($this->_filters[$key]);
break;
}
}
}
Error :
Fatal error: Call to undefined method SphinxClient::RemoveFilter() in
At a guess, you've modified the one that comes with sphinx, but the application itself is using a different 'sphinxapi.php' - maybe a locally installed one.
Or even you have the sphinx extension installed, so its providing the SphinxClient not 'sphinxapi.php`'- if so uninstall the extension.
Related
I'm playing around with Cloud Translation API v3 in PHP. I went through setup process and tried simple translation shown here and it worked. Then I wanted to test glossaries so I tried to add one as described here. When I'm trying to call the function:
protected function createGlossary()
{
$translationServiceClient = new TranslationServiceClient();
$projectId = 'my-project-id';
$glossaryId = 'my-new-glossary';
$inputUri = 'gs://bucket/file.csv';
$formattedParent = $translationServiceClient->locationName(
$projectId,
'us-central1'
);
$formattedName = $translationServiceClient->glossaryName(
$projectId,
'us-central1',
$glossaryId
);
$languageCodesElement = 'pl';
$languageCodesElement2 = 'en';
$languageCodes = [$languageCodesElement, $languageCodesElement2];
$languageCodesSet = new LanguageCodesSet();
$languageCodesSet->setLanguageCodes($languageCodes);
$gcsSource = (new GcsSource())
->setInputUri($inputUri);
$inputConfig = (new GlossaryInputConfig())
->setGcsSource($gcsSource);
$glossary = (new Glossary())
->setName($formattedName)
->setLanguageCodesSet($languageCodesSet)
->setInputConfig($inputConfig);
try {
$operationResponse = $translationServiceClient->createGlossary(
$formattedParent,
$glossary
);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$response = $operationResponse->getResult();
printf('Created Glossary.' . PHP_EOL);
printf('Glossary name: %s' . PHP_EOL, $response->getName());
printf('Entry count: %s' . PHP_EOL, $response->getEntryCount());
printf(
'Input URI: %s' . PHP_EOL,
$response->getInputConfig()
->getGcsSource()
->getInputUri()
);
} else {
$error = $operationResponse->getError();
// handleError($error)
}
} finally {
$translationServiceClient->close();
}
}
it returns an error:
Failed to build request, as the provided path (google.longrunning.Operations/GetOperation) was not found in the configuration.
It throws error at $operationResponse->pollUntilComplete();. The file in bucket contains just one line - test,test.
Then when I try to call function that lists all glossaries, it works but it doesn't return any.
What can cause this problem and how do I add glossary?
You need to install gRPC extension for PHP.
Info: https://cloud.google.com/php/grpc
Install gRPC for PHP
gRPC is a modern, open-source, high-performance remote procedure call framework. If you want to use PHP client libraries for gRPC-enabled APIs, you must install gRPC for PHP. This tutorial explains how to install and enable gRPC.
Install the gRPC extension for PHP.
sudo pecl install grpc
Enable the gRPC extension for PHP.
Add this line anywhere in your php.ini file, for example, /etc/php7/cli/php.ini. You can find this file by running php --ini.
extension=grpc.so
I have a legacy site (not written by me) that has been on a server with php5 on it for the last several years. I am in the process of creating a new server with php7 on it and testing what works and is broken.
the site uses pear by including the file pear/lib/DB.php. i created a brand new page that only has the code
<?php
require_once( "DB.php" );
?>
this presents the exact same error as the full site.
the error that's being presented is
PHP Parse error: syntax error, unexpected 'new' (T_NEW) in /local/sites/php/pear/lib/DB.php on line 310
the site only requires DB.php because I have added Pear to the php.ini in include_path
checking the version of Pear gives me the following
$ pear version
PEAR Version: 1.10.3
PHP Version: 7.0.15-0ubuntu0.16.04.4
Zend Engine Version: 3.0.0
Running on: Linux cdc-migration-0d 3.13.0-103-generic #150-Ubuntu SMP Thu Nov 24 10:34:17 UTC 2016 x86_64
from my research it shows the latest version of Pear is php7 compatible, so these should work together. any idea why just requiring the DB.php on a test page would immediately generate the parsing error?
edit:
the code in the pear file that is generating the error is as follows
function &factory($type, $options = false)
{
if (!is_array($options)) {
$options = array('persistent' => $options);
}
if (isset($options['debug']) && $options['debug'] >= 2) {
// expose php errors with sufficient debug level
include_once "DB/{$type}.php";
} else {
#include_once "DB/{$type}.php";
}
$classname = "DB_${type}";
if (!class_exists($classname)) {
$tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
"Unable to include the DB/{$type}.php file",
'DB_Error', true);
return $tmp;
}
#$obj =& new $classname; // ##### this is line 310 that generates the error #####
foreach ($options as $option => $value) {
$test = $obj->setOption($option, $value);
if (DB::isError($test)) {
return $test;
}
}
return $obj;
}
#$obj =& new $classname;
Assigning the return value of new by reference is deprecated since PHP 5.3. http://php.net/manual/en/migration53.deprecated.php
This is PHP4 style of writing PHP.
Write instead :
$obj = new $classname;
This has been removed as of PHP7.
See: http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.other.new-by-ref
I connect to Mongodb using the PECL PHP module Mongo. But I'm unable to find a solution to perform a custom server side sorting by passing an own Javascript function to the server.
$client = new \MongoClient( 'mongodb://localhost:27017', array() );
$collection = $client->selectCollection( 'mydata', 'users' );
$cursor = $collection->find( <my-query> );
$cursor->sort( <custom-sorting> );
In the Mongodb console this command works fine:
db.eval(
function() {
return db.users.find().toArray().sort(
function( doc1, doc2 ) {
return doc1.email < doc2.email;
}
)
}
);
But I'm unable to pass such a sorting function to the server using the PECL module. I found nothing in the documentation until yet.
How do I from PHP code if a PECL extension is installed or not?
I want gracefully handle the case when an extension is not installed.
I think the normal way would be to use extension-loaded.
if (!extension_loaded('gd')) {
// If you want to try load the extension at runtime, use this code:
if (!dl('gd.so')) {
exit;
}
}
get_loaded_extensions fits the bill.
Use like this:
$ext_loaded = in_array('redis', get_loaded_extensions(), true);
Have you looked at get_extension_funcs?
Couple different ways. You can just check for the existence of the class, or even a function: class_exists, function_exists, and get_extension_funcs:
<?php
if( class_exists( '\Memcached' ) ) {
// Memcached class is installed
}
// I cant think of an example for `function_exists`, but same idea as above
if( get_extension_funcs( 'memcached' ) === false ) {
// Memcached isn't installed
}
You can also get super complicated, and use ReflectionExtension. When you construct it, it will throw a ReflectionException. If it doesnt throw an exception, you can test for other things about the extension (like the version).
<?php
try {
$extension = new \ReflectionExtension( 'memcached' );
} catch( \ReflectionException $e ) {
// Extension Not loaded
}
if( $extension->getVersion() < 2 ) {
// Extension is at least version 2
} else {
// Extension is only version 1
}
I have upgraded PHP from version 5.2 to 5.3. Then upgraded the OpenId and library from 2.1.2 to 2.2.2. And also updated Yadis to latest. Before the upgrade, OpenId log-in was working. The underlying CMS is Drupal.
Now I get an Auth_OpenID_FailureResponse in the returned end point.
My code looks like below :
include 'common.php';
$consumer = getConsumer();
$response = $consumer->complete( BASE_URL . '/google/return' . urlencode($ext_param));
if( $response->status == Auth_OpenID_SUCCESS ){
echo "Successful status";
} else {
print_r( $response );
}
The trace looks like below (removed original domain name):
Auth_OpenID_FailureResponse Object (
[status] => failure
[endpoint] =>
[identity_url] =>
[message] => return_to does not match return URL. Expected http://xxx.xxxxx.com/ \
openid/google/return?from=accounts.google.com&janrain_nonce= \
2012-10-16T03%3A54%3A37Zudn8eJ, got http://xxx.xxxxx.com/openid/google/return? \
from=accounts.google.com&janrain_nonce=2012-10-16T03%3A54%3A37Zudn8eJ
[contact] =>
[reference] =>
)
This looks strange to me as the code is not modified but the library and the PHP version is upgraded. I searched online for any issues and read the documentations too.
Did I miss any thing or have to do any extra work for the upgrade ?
I was able to fix the issue by myself. The root cause was Drupal current path variable $_GET['q'] so it is removed from the $_GET parameters array and that made the OpenId return endpoint process success.
Code in the OpenID return end point :
function handle_openid_return () {
// unset the parameter 'q' from $_GET
unset($_GET['q']);
// Include
include 'common.php';
// Get the OpenID consumer
$consumer = getConsumer();
$response = $consumer->complete( BASE_URL . '/google/return' . urlencode($ext_param));
// Check the status of the $response object, for successful OpenID call
if ($response->status == Auth_OpenID_SUCCESS) {
...
} else {
...
}
}
I encountered the same issue in Drupal 6 with the latest php-openid. I had to strip the q= parameter from $_SERVER['QUERY_STRING'] before calling getConsumer() though.