I am working on a Symfony2 project. My project uses database to store the data and Doctrine2 to retrieve that data.
As the data within the database has grown the queries became very slow and the whole web app takes about 2 mins to load or does not load at all.
The only way I can see my self fixing this is to cache some queries results but how can I do that. Unless there is different way of dealing with such issue.
You need to have your cache driver installed and configured in doctrine configuration (result_cache_driver is important in your case). Once you have this done you can make Doctrine to use result cache by setting useResultCache(true)
$cachedResult = $doctrine->getManager()
->createQueryBuilder()
->(...)
->useResultCache(true)
->(...)
Check this blog post
NOTE: by default, in dev environment, result cache won't be used
EDIT: as you're using DBAL and not using ORM - SymfonyDoctrineBundle doesn't support this kind of cache out of the box, but you can add this support by yourself by following this detailed guide
In developer mode Symfony2 creates a new cache on every query. So suppose you have many queries then it will cache all queries one by one.
This takes more time than in production mode, because in production mode the cache will only be stored once.
Related
I'm using Laravel for developing my API, but I was curious if there is a way to boost the performance even more by disable the things I don't need.
Like the CommandBus and the services which Laravel uses to render the views itself, because I'm only returning JSON and not using the features like CommandBus, view rendering etc.
Not as far as I know, but the easiest thing to do to speed up your application would be to use route caching in Laravel 5.
Other than that, I guess general tips would be:
Use nginx instead of Apache
Use Myisam intead of innodb (if you're using MySQL and only doing reads)
Read/write master slave configuration to do reads from the slave.
What response time are you getting and what is the response time that you would like?
I was working with Silex and Doctrine ORM. To make my database queries faster, I wanted to have a caching of some sort.
I looked at PhpFastCache - which provides a good caching framework - but does not really integrate with Doctrine. The best part about this is that I can have a local cache independent of any external service - like memcached. Since I have a small site which is hosted on shared host, I cannot spend money on having a service on cloud.
I also looked at existing cache providers for Doctrine ORM and all of them use external cache service.
The last thing I know I would have to do is write a provider myself using the PhpFastCache, but just wanted to make sure that there is no alternative online that I can use. I have tried my best by searching online all day today, but I just wanted to make sure.
Just to add: I have looked at APC and Memcache, but I have my site on shared hosting, and I would need a dedicated hosting for installing the PECL modules for APC/Memcache :(.
Doctrine includes quite a few cache drivers that do not seem to be documented. There is not one for PhpFastCache, but there are two that cache directly to the filesystem. Check out FilesystemCache and PhpFileCache. You can see the full list in the repository.
If I had to guess, I'd say that FilesystemCache is what you want. It stores serialized data in a plain file. PhpFileCache stores it as a PHP file, and then uses include to read it later. That means it has to be parsed by PHP on read, which is probably slower unless you use a PHP bytecode cache like APC.
Neither solution will be as fast as something like Memcache since they both read from the filesystem instead of memory, but they should provide an optimization for slow database queries that are run often.
Edit: As Kiran Madipally pointed out, it should be easy create your own PhpFastCache driver by extending CacheProvider.
I quickly wrote a provider for PhpFastCache. I have added the gist here:
https://gist.github.com/thephoenics/ee7de9f95bfdf5f6c24f
I have a really nasty problem with a CodeIgniter application which I want to load balance using also MySQL replication.
In other PHP frameworks this would be a 5minute job because you may switch the datasource just before saving the data (CakePHP allows this, for example), but it seems in CodeIgniter that's a different story.
My problem is the application is legacy and I have to load balance it so I have all the hardware setup already done, the filesystem is in sync, the database has a slave and updates it as it should, but I have to make the second CodeIgniter application to read from the slave and write to the master.
I already found a solution but since the application is legacy I wouldn't want to go into its internals because I could destroy something that already works (it's also pretty sensible because people are paying within the app and it's also live which makes things even worse).
The solution I've found is this one which makes you change all the models in the application.
As further information CodeIgniter database driver (CI_DB_mysql_driver in this case) doesn't have any method for switching the connection or something.
Do you have another suggestion for tackling this problem? (besides changing all the models which I find a bit too intrusive)
I need to load data from an old DB into a migrated schema of this DB using Doctrine migration system.
I guess Doctrine might help me in this process.
I tried and lost a few hours using ETL scripts programs, without success.
From my point of view I need to :
Create a DB with the V0 schema
Load the data from the old DB (schema are identical)
Migrate DB to latest version using Doctrine migration
Extract data
Load it in the new DB
WHat do you think of this process?
Do you think it is feasable using Doctrine?
I tried a few searches on Google without success.
I am currently reviewed the features of Doctrine_Core class.
Thanks for your help
Yes, it is possible to migrate data from one database to another using Doctrine.
It sounds like you're trying to do a one-time database revision and migration and that your applications are not currently written using Doctrine. In that scenario, database abstraction has little or no benefit, unless you're also rewriting the applications to use it.
If you have no prior experience using Doctrine then I seriously doubt that writing custom migration classes in it will be easier than doing it with whatever database API you are already experienced using. It makes sense to use the migration classes (some times) if you are already using Doctrine for your development. Otherwise it's another layer and API you don't need.
I'm using Doctrine 1.2, which has some nice features for migrations but also a number of bugs and omissions of expected functionality. Reportedly version 2 improves on this but I haven't used it yet.
What do you think, should I use ORM like Propel or Doctrine?
For a new PHP Project. Are there any performance issues?
When you start a new project you can get Objects in and out of the database fast, without worrying how you do it.
You can also switch DBMS very fast from SQLite on your local dev machine, to MySQL on your testing or staging servers.
When the performance part kicks in, your application has already matured a bit, models are somewhat fixed and programlogic is running. Extending the models to use SQL instead of the ORM is more convenient then, because the structure of the project isn't changing (so fast) anymore.
I suggest doctrine.