I've got some problems with Doctrine 2 on my localhost. One page, which uses only one query, is loading on localhost in about 1.5s. Meanwhile, on remote server loading takes about 300ms (http://gieromaniak.pl/contact). I have no idea what could be wrong. Is it Doctrine 2 configuration or sth else? Or maybe I don't have some PHP extension on my server (WAMP - Apache 2.4.2, PHP 5.4.3)?
Nevertheless, I'm including source code of my Doctrine configuration file:
<?php
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Doctrine\DBAL\Types\Type,
Doctrine\Common\Cache\ArrayCache,
Doctrine\DBAL\Logging\EchoSqlLogger;
// include the class loader directly
require_once __DIR__ . '/Doctrine/Common/ClassLoader.php';
$doctrineClassLoader = new ClassLoader('Doctrine', __DIR__ . '/');
$doctrineClassLoader->register();
Config::load('base');
Config::load('database');
if(Config::get('base.mode') == 'development') {
$bProxyGen = TRUE;
} else {
$bProxyGen = FALSE;
}
// Set up caches
$cache = new ArrayCache;
$config = new Configuration;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
// Metadata Driver
$driverImpl = $config->newDefaultAnnotationDriver($models);
$config->setMetadataDriverImpl($driverImpl);
// Proxy configuration
$config->setProxyDir(PATH_ROOT.Config::get('database.proxy_dir'));
$config->setProxyNamespace(Config::get('database.proxy_namespace'));
$config->setAutoGenerateProxyClasses($bProxyGen);
// Database connection information
$connectionOptions = array(
'driver' => 'pdo_mysql',
'charset' => 'utf8',
'dbname' => 'dbname',
'user' => 'username',
'password' => 'password',
);
// Create EntityManager
$entityManager = EntityManager::create($connectionOptions, $config);
Thank You in advance for any help!
I would recommand to install apc and to improve mysql performance:
Install APC
I strongly recommend to use Wamp server (x86) for that, the apc.dll for the x64 version of windows doesn't work well.
follow this tutorial with the following modifications:
the link to apc.dll
find the Zend Extension Build or PHP Extension Build ,from your phpinfo(); you can use that http://localhost/?phpinfo=1 for your WAMP localhost
the Zend Extension Build should be like this :
API220100525,TS,VC9
Note the TS word, it can be blank; look if their is a different word like NTS
download the latest version according to the TS or NTS value
rename the dll php_apc.dll
put the php_apc.dll in YourWampFolder/bin/php/ext/
there are 2 php.ini files in wamp : wamp\bin\apache\apacheX.X.XX\bin\ and wamp\bin\php\phpX.X.X\ (replace the X.X... by your versions)
write extension=php_apc.dll; in both of them
close/open Wamp (not restart)
from the wamp icon->php->PHP extensions->php_apc.dll check to activate
restart wamp
you can verify that APC is running by downloading the apc.php file into your project dirctory. You will find it in the compressed file available at the PECL website. Take the latest version.
Now from your browser : http://localhost/yourproject/apc.php
You can modify the settings of APC from php.ini (try both)
exemple :
//php.ini
...
[APC]
apc.ttl=7200
apc.user_ttl=7200
apc.shm_segments=3
apc.shm_size=90M
apc.max_file_size = 2M
apc.include_once_override = 1
just in case you want to clear the cache
// resetcache.php
<?php
if ( $_GET['pass'] == 'yes') {
if(function_exists('apc_clear_cache')){
if (apc_clear_cache() && apc_clear_cache('user'))
print 'All Clear!';
else
print 'Clearing Failed!';
print '<pre>';
print_r(apc_cache_info());
print '</pre>';
}else print "fuction_doesn't exist";
} else {
print 'Authenticate, please!';
}
i put some extra security to prevent unwanted access but do not include apc.php and clearcache.php in the production server.
Increase Mysql performance
link1
link2
link3
Clean local machine
You can clean your browser cache and temp folders. CCleaner
This is all that i did to increase the speed of Doctrine2 on my local machine in the past.
you can also monitor the Ram used by Mysql/Apache process to see if you don' t need to buy/allocate more RAM.
Related
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.
I've no real knowledge about installing an extension. I'm stuck because I cannot use SQRT in SQLite.
I'm using Laravel on a local machine and I'm working on my PHPunit Tests. In one Test I'm using a query with some heavy math functions.
I get the error:
Caused by
PDOException: SQLSTATE[HY000]: General error: 1 no such function: SQRT
I found out that SQLite has an extension called: extension-functions.c
I downloaded it, but I'm not sure if I did everything correctly (obviously not because it does not work):
I downloaded it and used this in my terminal
gcc -fno-common -dynamiclib extension-functions.c -o libsqlitefunctions.dylib
It compiled this data: libsqlitefunctions.dylib
With php --ini if found that my php.ini is located in /usr/local/etc/php/7.1/php.ini
Now I looked up for sqlite3 and found this commented ;sqlite3.extension_dir =
I changed it to
sqlite3.extension_dir =/usr/local/etc/php/7.1/extension/libsqlitefunctions.dylib
and created the extension folder and put the dylib file inside
I restarted my apache with sudo apachectl restart
And tried my Query and still, it fails. What did I do wrong?
For future readers
To use it in Laravel you call it like this:
$pdo = DB::connection()->getPdo();
$pdo->sqliteCreateFunction('SQRT', 'sqrt', 1);
$pdo->sqliteCreateFunction('ASIN', 'asin', 1);
$pdo->sqliteCreateFunction('SIN', 'sin', 1);
$pdo->sqliteCreateFunction('COS', 'cos', 1);
$pdo->sqliteCreateFunction('POWER', 'pow', 2);
$pdo->sqliteCreateFunction('pi', 'pi', 0);
It seems that you want to use this with PDO. The problem is that loading extensions only works with the SQLite3 api directly, using the SQLite3::loadExtension method.
The PDO driver does not allow the loading of extensions (see this wiki entry regarding LoadableExtensions under "Security Considerations").
So you could either swith to the SQLite3 api directly or you could use "user defined functions" with PDO. For example if you need the SQRT function:
$db = new PDO('sqlite:testdb.sqlite', null, null, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
$db->sqliteCreateFunction('SQRT', 'sqrt', 1);
$stmt = $db->query("SELECT sqrt(25)");
foreach ($stmt as $row) {
echo $row[0], PHP_EOL; // output: 5.0
}
Most of the math-functions your extension provides map 1:1 to the PHP function names (like sqrt), so it should be easy to create the functions you need.
It seems you are pointing the sqlite3.extension_dir property at a file instead of a directory. According to the manual for sqlite3, the extension_dir property is:
[The] Path to the directory where the loadable extensions for SQLite reside.
I think it may work if you change
sqlite3.extension_dir = /usr/local/etc/php/7.1/extension/libsqlitefunctions.dylib
to
sqlite3.extension_dir = /usr/local/etc/php/7.1/extension
However, I would create a separate directory for the SQLite3 extensions so they are not mixed with the PHP extensions; I say this since it seems like you are currently using the PHP extension directory for the sqlite3.extension_dir property. (If you aren't, then please disregard this note.) I assume that SQLite3 just scans the configured directory for loadable modules and loads them using something like dlopen. This might conflict if it tries to load a PHP extension. (Who knows, it may gracefully handle this.)
I am trying to connect to MongoDB via PHP.
mongod --version
db version v3.2.8
Then,
php -i | grep mongo
/etc/php/7.0/cli/conf.d/20-mongodb.ini,
mongodb
mongodb support => enabled
mongodb version => 1.1.8
mongodb stability => stable
libmongoc version => 1.3.5
mongodb.debug => no value => no value
I tried:
sudo pecl install mongodb
which returns
pecl/mongodb is already installed and is the same as the released version 1.1.8
install failed
which (the install failed bit) gets redressed if I try:
sudo pecl uninstall mongodb
and
sudo pecl install mongodb
I have this php file:
<?php
echo "I am here";
$connection = new Mongo('localhost');
$db = $connection->mydb;
$list = $db->listCollections();
foreach ($list as $collection) {
echo "$collection </br>";
}
echo "I am never here";
?>
I cannot see the second echo.
I would appreciate any thoughts.
Thank you.
First, check #sanjay comment and then apply this connection:
$db = new MongoClient('mongodb://localhost', [
'username' => 'root',
'password' => '',
'db' => 'YOUR DB'
]);
Hope it will work for you.
I managed to have it working. Thanks to this post:
After upgrading PHP to version 7, why can't I use the mongodb driver?
and this post:
Using the PHP Library for MongoDB (PHPLIB)
Sorry as it seems pretty odd (to me!) but indeed: MongoClient() has become (verbatim! with the slash!) MongoDB\Client().
Hence, the file I had in my original post becomes:
<?php
require 'vendor/autoload.php';
echo "I am here";
$manager = new MongoDB\Client();
$database = $manager->mydb;
foreach ($database->listCollections() as $databaseInfo) {
var_dump($databaseInfo);
}
echo "I managed to arrive here";
?>
and I can see the contents of mydb as well as the 2 echos. The vendor/autoload.php was generated by
sudo composer require "mongodb/mongodb=^1.0.0"
as I ran it from within the directory of the php file above. Probably not the best idea as I, now, have to resolve how to make the autoload.php (and all it carries with) globally available. But, nonetheless, at least, I managed to arrive somewhere.
I am using: PHP 7.0.8-0ubuntu0.16.04.2 (cli) ( NTS )
under: Ubuntu 16.04.1 LTS
I am running a PHP 5.4 hosted Web App on Azure. To manage session handling I have configured a Redis cache instance on Azure.
I have set the session save path & handler:
session.save_handler = redis
session.save_path = "tcp://kbcache.redis.cache.windows.net:6379?auth=***"
I have also configured the Redis extensions:
PHP_EXTENSIONS bin\php_igbinary.dll
APPSETTING_PHP_EXTENSIONS bin\php_igbinary.dll
PHP_EXTENSIONS02 bin\php_redis.dll
APPSETTING_PHP_EXTENSIONS02 bin\php_redis.dll
However when I browse to my website I receive the message:
Warning: session_start(): Cannot find save handler 'redis' - session
startup failed in D:\home\site\wwwroot\index.php(22) : eval()'d code
on line 2
What am I missing?
[Update Pre post]
When deployed PHP project, we need enable extensions on Azure.
Please see my website folder structure:
I copied the DLL files into folder named ext. And those dlls' version should be VC9 and non-thread-safe (nts) compatible.
And I created a extension.ini into folder name ini. The content as following :
extension=d:\home\site\ext\php_igbinary.dll
extension=d:\home\site\ext\php_redis.dll
zend_extension=d:\home\site\ext\php_xdebug-2.3.3-5.4-vc9-x86_64.dll
session.save_handler = redis
session.save_path = "tcp://**.redis.cache.windows.net:6379?auth=**
At last, I add the "PHP_INI_SCAN_DIR" Configurtation Panel on Azure portal:
It works for me.
Actually, I tried PHPRedis extension on my environment, it works fine.
Form your description, I think you made configuration of Redis extensions complicated.
I followed those steps:
1.Switch to PHP version 5.4
2.Download PHPRedis extension form this page.
Since I used PHP which version is version 5.4 TS, I downloaded phpredis_5.4_vc9_ts
3.After unzipped the download file, Please copy those DLL file into your PHP ext folder. It seems that you need pay attention to this point.
Add this code into your PHP.ini file
extension=php_igbinary.dll
extension=php_redis.dll
session.save_handler = redis
session.save_path = "tcp://**.redis.cache.windows.net:6379?auth=**
4.Create a Page and test Redis Code:
$redis=new Redis();
$redis->pconnect('tcp://**.redis.cache.windows.net', 6379);
$redis->auth('**+**=');
$redis->set('key', 'hello ');
$redis->append('key', 'world ');
echo $redis->get('key');
had similar issues. make sure redis dll file is there and enabled in php.ini also make sure that redis folder has full write permissions.
I got this error :
CakePHP is NOT able to connect to the database.
Database connection "Sqlserver" is missing, or could not be created.
Details :
CakePHP 2.5.4
Wamp server 32-bit
Dreamweaver CS6
SQL Server 2014
On my details.php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Sqlserver',
'persistent' => false,
'host' => 'localhost\MSSQLSERVER',
'database' => 'testing'
);
I have load both the extension on both ext folder (apache & php) and on php.ini
extension=php_sqlsrv_55_ts.dll
extension=php_pdo_sqlsrv_55_ts.dll
Searched everywhere but still cannot connect to sqlserver.
note : I can connect to MySQL but not SQLServer
Maybe bacause you're not running sqlserver? Wamp is configured with apache/MySQL... hence the WAMP acronym...
In which case your config file should be similar to the one given in this example...
http://book.cakephp.org/2.0/en/development/configuration.html
Try to edit another php.ini in C:\wamp\bin\apache\Apache2.x.x\bin\ then restart apache.
Also the SQL Server Native Client must be installed for the extension to work.
In the end, i've found the solution. It's the problem of WAMPP server. Tho i have it installed on other machine and it works, it's not the same with the machine i'm currently using. So what i do is:
Uninstall WAMPP
Install XAMPP
Configure php.ini on apache and php
Load extensions in the ext folder of php
Note : I did the same configuration with WAMPP earlier
Then everything works like a charm.