We are using a Lumen 5.2.x (Laravel) application to get data from a Oracle Database. For that reason we use oci_connect() to connect to the database. (Extra info: we use Oracle instantclient)
For a reason unknown, the application was not responsive and wouldn't return any data. After lots of hours debugging we found out that it got stuck in that very same method: oci_connect(). Apparently the function did not return a 'time-out'-message or anything similar.
Later, it seemed the database moved to another host, which is the reason it couldn't connect. However, we expected a error, instead of a huge amount of waiting.
This is the reason we are trying to force a time-out to be set, until now this has not worked out.
Things we have tried:
Adding this to the connection string: (CONNECT_TIMEOUT=10)(RETRY_COUNT=3) which is completely ignored.
Setting max_execution_time and set_time_limit to 1
Adding a sqlnet.ora with settings:
TCP.CONNECT_TIMEOUT=10
SQLNET.INBOUND_CONNECT_TIMEOUT=10
SQLNET.OUTBOUND_CONNECT_TIMEOUT=10
Everything we have tried failed, does anyone know how to work around this bug? Any help is appreciated!
Edit:
System info:
Windows Server 2012 R2, IIS 8, PHP 5.6
below is laravel package used for oracle, you can try this,
laravel package for oracle
I copied the oracle array from oracle.php to the database.php config file and the issue has gone away.
Contents of my oracle.php file:
return [
'oracle' => [
'driver' => 'oracle',
'tns' => env('DB_TNS', ''),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1521'),
'database' => env('DB_DATABASE', ''),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'charset' => env('DB_CHARSET', 'AL32UTF8'),
'prefix' => env('DB_PREFIX', ''),
],
];
Unfortunately, oci_connect is already too high-level a function to allow timeout control - OSI model layer 5, if you consider it is there to establish a session for what follows. I suggest you try fsockopen on port 1521, level 4, which 5th argument sets the timeout in seconds. If fsockopen() returns a valid resource, then proceed with oci_connect(), otherwise report error / throw exception.
I checked it today, part of a "preflight assessment" when establishing four Oracle connections with various remote sites. It actually gives up after timeout seconds!
You have tried several approach, which is great. The max_execution_time is a good one. You can register a shutdown function so that you can log the error if any - or do whatever you need.
<?php
function shutdown(){
$error=error_get_last();
if(is_null($error))
echo "No errors"; //or do nothing
else
print_r($a); //or log it properly
}
register_shutdown_function('shutdown');
ini_set('max_execution_time',3 );//max 3 seconds
sleep(5); //just for test it out
In any case, according to the web (for instance : "don't loose your head, move to Linux"), you should try using Linux to run your webserver when working with Oracle connection, if possible).
(I know that there were, at some time, a lot of rage between Linux and Windows People. But if operating system is more suited for some use case, why bother using the other)
From the docs:
"Sometimes Oracle doesn't cleanup shadow processes when accessed from PHP. To avoid that, check your
$ORACLE_HOME/network/admin/tnsnames.ora file in your Oracle Client directory and remove the (SERVER=DEDICATED) token if is set.
To let Oracle delete shadow process on timeouts, add the following line in your
$ORACLE_HOME/network/admin/sqlnet.ora
found in your ORACLE Server directory:
SQLNET.EXPIRE_TIME=n
Where 'n' is the number of minutes to let connection idle befor shutting them out."
Have you tried this?
i am working on Redis to store data Everything is working fine in my local system. i have successfully installed redis also in laravel with this command composer require predis/predis also and Redis setup of window also installed. Now when i store data in Redis like this:-
Redis::set('first',"My first Test"); // put data in Redis key
echo Redis ::get('first'); // get data
Above code is working fine in my local system. when i try to use this code in live server it is showing the below error:-
Please help me to resolve this issue. We are using amazon-ec2 server Thanks in advance :)
I had the same issue. But I believe its related to php 7 rather than Larevel 5.4 because I'm using Laravel 5.1 and I still have the problem.
I came across 2 solutions
Use use Illuminate\Support\Facades\Redis; instead of use Redis; if you want to call the Redis methods statically.
Change to dynamic calling
$redis = new Redis();
$redis->set('boo','Have beer and relax!')
$redis->get('boo');
Just remove or comment out extension=php_redis.dll from your php.ini
Laravel and server Redis conflicts with name "Redis"
This will work
In Laravel database config you can define a client for your Redis handler.
As you have installed predis, your Redis database configuration should look like this
'redis' => [
'client' => 'predis',
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
PhpRedis extension and Laravel alias for Redis Facades are same which is creating the issue. In case you want to use the PhpRedis extension you need to change the alias keyword defined in app.php and client in the database config.
I have a Yii2 framework connected to an SQL Server 2012 database.
I have already configured the config/db.php file as follows:
return [
'class' => 'yii\db\Connection',
'dsn' => 'sqlsrv:Server=localhost;Database=Evaluators;MultipleActiveResultSets=true',
'username' => '_myUsername_',
'password' => '_myPassword_',
'charset' => 'utf8',
];
I have also installed the necessary extension files in the /ext directory.
I am using SQL Server 2012 instead of MySql.
When I try to Start Gii Model Generator I get the following error :
Database Exception – yii\db\Exception could not find driver
Caused by: PDOException could not find driver
Any ideas what should I change or do?
The issue can be from your php configuration.
In that case, I solved it by doing the following: uncomment extension=php_pdo_mysql.dll in your php.ini. (I am on MySQL instead of SQL server 2012)
More explanations here: https://www.jeffgeerling.com/blog/2018/installing-php-7-and-composer-on-windows-10
Since your using SQL server 2012, I cannot confirm for sure, but you should investigate this: https://www.php.net/manual/en/ref.pdo-sqlsrv.php
Good luck
There have been several other posts about this, but none of the answers seemed to work for me.
When I navigate to the CakePHP page on my local machine, there is one error:
Cake is NOT able to connect to the database. Database connection
"Mysql" is missing, or could not be created.
When I run this helpful code in my home.ctp, I get the following response:
Error!: SQLSTATE[42000] [1049] Unknown database 'test'
However, my Users/Ben/Sites/myapp/app/Config/database.php looks like this (I set MAMP to look for the document root in Users/Ben/Sites):
<?php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'Ben',
'password' => 'mypass',
'database' => 'CV',
);
}
I have created a mysql user called Ben with password mypass and created a database called CV under that. Moreover, I can't find mention of a test database anywhere. Help?
Try adding the socket:
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
An alternative to unix_socket (especially for OS X people) is to replace localhost with 127.0.0.1
Would be as Follows :
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => '127.0.0.1',
'login' => 'user',
'password' => 'password',
'database' => 'database-name',
'prefix' => '',
'encoding' => 'utf8',
);
Edit php.ini and add:
extension=php_pdo_mysql.dll
Then restart your web server
On Mac, using MAMP as a development platform, for cake the correct solution is using Domingo Casarrubio solution.
Add the unix_socket parameter to your database configurations.
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
This error can also be caused if your connecting database user doesn't have the proper privileges. I believe you only need a minimum of INSERT, SELECT, UPDATE, and DELETE.
Always check username/password and the user privileges first since CakePHP will most likely give a vague database connection error for either.
I noticed that you've had asked this an year ago, and most probably would've solved this by now. However, for those facing the same issues when attempting to install CakePHP on XAMPP, all you have to do is change the 'login' to 'root', i.e. the default login of XAMPP, and leave the 'password' as '', i.e. blank. The complete code in your database.php file should look like this:
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'ckblog',//replace with your own database name
'prefix' => '',
//'encoding' => 'utf8',
);
That's it.
I had the same problem and found out eventually that it was caused by CakePhp not accepting that I used a user with a password, even if that user was created in PHPMyAdmin. I had to use the user 'root' with no password.
I found this out after making the following change to the file /lib/Cake/Error/exceptions.php.
The original line:
protected $_messageTemplate = 'Database connection "%s" is missing, or could not be created.';
is changed into this instead (note the change from single to double quotes):
protected $_messageTemplate = "Database connection \"%s\" is missing, or could not be created:\n %s";
This will give you the reason for the problem so that you may change the cause properly.
I have had this problem since upgrading to OSX Yosemite and inserting following line did the trick for me:
'unix_socket' => '/tmp/mysql.sock'
It can be that mysql PDO support is missing.
as root (or using sudo):
apt-get install php5-mysql
Just to help Ubuntu users out:
I had the same error in my ubuntu 13.10 machine with the newest xampp downlaoded directly from apachefriends. Tried most of the stuff in every post I could find about this error, but not the mac-specific stuff.
In the end, the fix happened to be the same as the elected answer here:
Find the socket that mysqld creates for programs to connect to:
user#host /opt$ find . -name mysql.sock
/opt/lampp/var/mysql/mysql.sock
add it to your cakePHP database configuration file (cakePHP)/app/Config/database.php
'unix_socket' => '/opt/lampp/var/mysql/mysql.sock'
To me, this finally resulted in my cake commands being able to be executed without the "Error: Database connection "Mysql" is missing, or could not be created.".
Because, cake bake use unix socket for connecting to database
so that you need add unix_socket for connection string.
You have to confirm location that store mysql.sock in WAS
Example: in my case i'm using xampp on MACOS 10.11
(edit file Config/database.php)
public $default = array(
‘datasource’ => ‘Database/Mysql’,
‘persistent’ => false,
‘host’ => ‘localhost’,
‘login’ => ‘root’,
‘password’ => ‘root’,
‘database’ => ‘cakephp’,
‘encoding’ => ‘utf8’,
‘unix_socket’ => ‘/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock’
);
Finally, It's work for me!
What did it for me in the end was that I had created a table in my database, but there was no data in it.
In order for CakePHP to recognize the MySql connection, there has to be a table with data in it.
You might need to create the table in your php file... Open up phpMyAdmin and check to ensure that they database CV exists.
It's your model. Open that up and there must be the following line
public $useDbConfig = 'local';
This overwrites global config & set it back to local
I tried splicing the code from Example 2 of http://php.net/manual/en/pdo.connections.php into /app/View/Pages/home.ctp. I had to fix the arguments the PDO constructor and change the name of the table in the query. The example 2 code returned the error "Error!: could not find driver". Based on King Jk's answer I was attempting to modify the php.ini when I started to wonder where a php_pdo_mysql.so might live. http://php.net/pdo_mysql showed how it was compiled as part of PHP via the --with-pdo-mysql option to configure. Recompiling fixed my problem. Note I'm working on a Ubuntu 12.10 system with PHP 5.5.9 and Apache Webserver 2.4.6
In my case it was because the database didn't exist. I expected running ./app/Console/cake schema create would create it but it did not. Creating it with create database <database name> in mysql did the trick (although I had already assigned privileges).
I've been struggling with this the whole weekend and finally solved it. Turns out that the php.ini is pointing to a non-existing "extensions dir". Create a phpinfo() file and look at the value of this field:
I noticed that in the mamp php installed folder there is a no-debug-non-zts-20131226 folder, which is different from the value shown in the phpinfo(). What I did was to clone this folder and changed the name to the value of the phpinfo(). Probably you could modify the php.ini file but I didn't want to.
I don't know if you solved your problem, but I'm posting this because my problem was different and google took me here, so I hope to help future googlers having a similiar issue.
Hope this helps.
If you're on Godaddy (or any other shared hosting for that matter), they may be limiting outgoing connections to ports 80 and 443 only.
System configuration:
Fedora 32
php-fpm 7.4.13
mariadb 10.4.17
CAKE 2.10.17
Error message from CAKE:
Database connection "Mysql" is missing, or could not be created.
Enhanced error message using answer at https://stackoverflow.com/a/24722976/5025060
Database connection "Mysql" is missing, or could not be created: Selected driver is not enabled
My problem was no "connector" between PHP and SQL was installed. The solution was:
dnf install php-mysqlnd
This allowed PHP to connect to the database as specified in CAKE's database.php configuration file.
I have gotten the latest CakePHP (2.1.0) and MongoDB Datasource Plugin both from git, and have followed the configuration settings as best as I can. I have placed the MonogoDB plugin in the plugins directory, and updated both my database.php and bootstrap.php files:
bootstrap.php:
CakePlugin::load('Mongodb');
database.php:
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Mongodb.MongodbSource',
'database' => 'database',
'host' => 'staff.mongohq.com',
'port' => 10070,
'login' => 'user',
'password' => 'secret'
);
}
I'm afraid I'm missing something stupid, but I keep getting the error:
Datasource class MongodbSource could not be found.
Which to me, implies it can find the plugin, but not the datasource class. Anyone seen this before? I've also tried to connect to a locally installed MongoDB, but same error persists.
Use this command to pull the plugin so it pulls the cake2.0 branch instead (which uses the correct cake 2.x directory naming conventions):
git clone -b cake2.0 git://github.com/ichikaway/cakephp-mongodb.git Mongodb
Please make sure that you are using the CakePHP-Mongo plugin for CakePHP 2.0 and not CakePHP 1.3