running Cassandra from php shell command (using datastax php-driver) - php

I am able to run it through the browser but not from command line
ie php test.php
$raw = Cassandra::cluster()
->withContactPoints('localhost')
//->withCredentials($this->username, $this->password)
->build();
var_dump($raw);
die;
from browser:
object(Cassandra\DefaultCluster)#2 (0) { }
command line:
PHP Fatal error: Class 'Cassandra' not found in /var/www/html/test.php on line 2
Is it possible to get same from command line as well?

The cli uses a different php.ini file (e.g. /etc/php/7.0/cli/php.ini & /etc/php/7.0/fpm/php.ini). You are probably not including the extension in the cli one.

Related

Php artisan serve require fatal error after upgrading php7

After upgrading php from 7.0.14 to 7.0.26 php artisan serve throws this error
Warning: Unknown: failed to open stream: No such file or directory in
Unknown on line 0
Fatal error: Unknown: Failed opening required '/Applications/XAMPP/xamppfiles/htdocs/school-dashboard/public/server.php'
(include_path='.:') in Unknown on line 0
Ok, after hours of pulling my hair out I finally found out what the issue was.
In laravel 4 php artisan serve does this under the hood
<?php
namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
class ServeCommand extends Command {
public function fire()
{
$this->checkPhpVersion();
chdir($this->laravel['path.base']);
$host = $this->input->getOption('host');
$port = $this->input->getOption('port');
$public = $this->laravel['path.public'];
$this->info("Laravel development server started on http://{$host}:{$port}");
passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t \"{$public}\" server.php");
}
}
That is essentially this in plain php:
php -S 127.0.0.1:8000 -t public serve.php - see the docs for php built in server for more info.
And this worked well and dandy before php 7.0.26, where the last parameter for the php -S built in server was changed to a flag as well, so you have to call it like this php -S 127.0.0.1:8000 -t public -f serve.php.
If you want to serve it with php artisan serve you will have to override the ServeCommand and change the last line of the fire() method to this:
passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t \"{$public}\" -f server.php");
Or you can change it directly in the ServeCommand, but if you do a composer update or install you will have to do it again.
That's what it happened to me today running a Laravel project. After i have tried all the possible solutions finally i got one that it's work for me . So first of all check that your anti-virus block your server.php and it also deleting it . Then check if you server.php is missing from your project, and I think that is probably yes . Just copy it (server.php) from other project (build also from laravel) but before that just turn off your anti-virus until your next restart and make you sure that you will stop it every time before running. I hope that it helps you.

oci_pconnect error when ran in windows task scheduler

I'm trying to run a script that imports data from an Oracle table into a Mysql table. I'm using oci_pconnect to connect to Oracle. Everything is running fine when the script is executed in the browser but i'm getting the following error when the script is run in cmd under Windows
Fatal Error: Call to undefined function oci_pconnect()
I'm calling the php script in cmd by the following code
#echo off
php C:\wamp\www\somefile.php
echo Done!
pause > nul
Thanks in advance!!
To avoid having this error, just go to php.ini located in your PHP folder and uncomment the line of the oci function in the extensions section:
;extension=php_oci8.dll
problem solved!

phpunit not recognise curl while its activated on wamp server

hi i'am using phpunit with selenium webdriver.
when i make this cmd
phpunit myfile
i get this error message
Call to undefined function curl_init().4.3\pear\PHPUnit\Extensions\Selenium2TestCase\Driver.php
my code is
<?php
class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://www.google.com/');
}
public function testTitle()
{
$this->url('http://www.google.com/');
$this->assertEquals('google', $this->title());
}
}
?>
some says to check my curl i have to cmd this
php --ini
but the response outed in many line ,there are some line outed before but hidden
how te see the previous line on the DOS ?
Enable curl by clicking on wamp server icon on the task bar and click php then select php extension and select curl and also verify that u have this line in your php.ini
php extension=php_curl.dll
for more refer this php.net/manual/en/book.curl.php
Remember that phpunit is probably run in the command line and the command line uses a different php.ini
If you want to find out, which one would be the correct php.ini, just run this command in the command line:
php -i | find /i "Configuration File"
I solved the problem by copying php.ini from apache to my php folder.

imagecreate() works fine when php script in ran from browser , but not when it is run from the shell

I have image creating php script . It works fine when i access it from the browser . But when it is called from a shell script it shows the following error .
PHP Fatal error: Call to undefined function imagecreate()
PHP CLI probably doesn't use the same configuration file than the browser one. So it doesn't load the GD library.
You could either force him to use the same .ini file :
php -c /directory/php.ini phpscript.php
Or add the following line in your PHP CLI configuration file :
; Enable gd extension module
extension=gd.so
You can check if the gd is loaded and try to load it dynamically
<?php
if (!extension_loaded('gd')) {
if (!dl('gd.so')) {
echo "GD cannot be loaded";
exit;
}
}
?>

PHPUnit fatal error 'call to undefined function xcache_get()' AWS SDK & Symfony 2

I'm trying to get PHPUnit up and running in my Symfony 2 app, but I'm running into a problem I can't seem to figure out.
When I run my unit test a Fatal Error is returned, this does not happen inside of a normal browser.
Test function
$client = static::createClient(array(), array(
'PHP_AUTH_USER' => 'test',
'PHP_AUTH_PW' => 'test',
));
$crawler = $client->request('GET', '/test/url');
Error in console
$ phpunit -c app/
PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from /Acme/app/phpunit.xml.dist
PHP Fatal error: Call to undefined function xcache_get() in /Acme/vendor/aws-sdk-for-php/lib/cachecore/cachexcache.class.php on line 58
Fatal error: Call to undefined function xcache_get() in /Acme/vendor/aws-sdk-for-php/lib/cachecore/cachexcache.class.php on line 58
Line error refers to (In AWS SDK) L 58 is L 3 in this excerpt
public function read()
{
if ($data = xcache_get($this->id))
{
$data = $this->gzip ? gzuncompress($data) : $data;
return unserialize($data);
}
return false;
}
Any help much appreciated :-)
phpunit is using different ini file that does not load this extension
Try running php --ini from console, compare it with phpinfo() output from the browser to see what ini files are being loaded (most probably your web server runs on different user and may have it's own ini file)
Possible ways to fix it:
Editing ini used by cli and adding necessary options
By setting PHPRC enviroment variable to point to MAMP ini file
Create symlink to the MAMP ini file in php bin folder
Edit phpunit file and add -c path/to/ini after php binary

Categories