Change MongoDB sizeOnDisk when i create a new database - php

I used PHP to create MongoDB database. My problem is that every time I create a database, the database's "size on disk" is some 200MB. I want to reduce it down to 25-50MB every time.
I have tried to use "command" and look in the .conf file for MongoDB without luck.
I run CentOS 6.2 if it helps.

If you run the command mongod --help you will see various options you can add when you start-up MongoDB. Two you may want to research are:
--noprealloc disable data file preallocation - will often hurt
performance
--smallfiles use a smaller default file size

Related

Using git version control for PHP development

Is it possible to version control a PHP + MySQL + Apache project? And could it keep track of the changes in the database, like for example if I added a new table, can I possibly commit that?
Thank you.
It is not normal to keep databases in version control. Some developers use a sqlite database for development so that it can be checked into version control, but this can lead to issues as sqlite syntax can be different from MySQL.
However, you can keep your database schema and migrations source control. Look at a projects such as mysql-php-migrations to get started.
There's a good tutorial on using PHP with Git at http://net.tutsplus.com/tutorials/other/easy-version-control-with-git/ - this should get you started.
Using Git for your PHP scripts is no problem, however tracking changes to the database is a little trickier. If you have SQL scripts that create the database structure then these can be version controlled with no problems. Otherwise you could use mysqldump to output the structure to an SQL script after any changes you make:
mysqldump -d -h localhost -u root -pmypassword mydatabase > dumpfile.sql
You could use git to track PHP scripts and SQL scripts that create the necessary database structure. Those SQL scripts could of course be version controlled and recreate the database schema at any given state.
Git is essentially SCM, which means Source Control. Tables in mysql are stored as binary files, so it isn't very good idea.
You can, however, store SQL queries which create these tables, allowing you to re-create them if you needed to.
As for php, it will be all good.
I recently released a really simple shell script that will help keep changes to a MySQL database under version control.
https://github.com/stevecomrie/mysql-version-control

How to access an SQLite database file stored on cd using php?

I have a small mySQL database and a few simple php based webpages that query the database, generate html tables and present them in the browser. The database is no longer being updated. So, searching and viewing subsets of the data is all that is required.
Some users are interested in distributing the searchable database on a cd or usb memory stick. SQLite seems to offer the answer, but I don't understand what is needed to make this work. What will be required to make a web browser based "app" work from a memory stick in the absence of a server like xampp?
XAMPP Lite from http://portableapps.com/apps/development/xampp
What you want is called a "standalone server". This is very common in almost every other modern language except PHP, for some reason. Googling "standalone php server" reveals several options:
QuickPHP
Nanoweb
Server2Go

How would you implement an auto-update for a standalone PHP project using GitHub?

My project is a collection of PHP scripts using MySQL as a database and needs to be installed locally using WAMP/LAMP/MAMP.
Previously I've been sending the users a link to a zipped archive and having them overwrite it, but since I took the plunge to GitHub, I've realized that there are far better ways; namely Service Hooks in GitHub. However, this would work fine as long as I don't alter the database in any way, which is a good possibility.
I've been toying with the idea of how I would implement this, but I can't find a clear solution. So far I've concluded with that I need to have a directory (say update/) which contains .sql files for each update. The PHP script will then check said directory for a file corresponding with the new version number (not sure how I will define a version number; I was thinking of using the commit ID, but that won't be available until after the commit, so...).
I would love some input on this!
Here's how I would tackle this (not the most elegant or performant):
Add a flag in the DB with a version number
Add a min-version number in your DB layer PHP file
Check that the DB version is greater than the min-version
If it is: continue about your business
Else: Run the PHP file in update/ which would have a series of ALTER TABLE commands to be run on the DB server
Update the min-version number in the DB to the latest number
All done
Alternately instead of querying the DB you can have a file which is generated by your DB interface PHP file (and ignored with .gitignore) which you can just as above.
I would really recommend checking out Doctrine and its migration feature.
This does exactly what you are looking for, plus you get a very nice tool for working with all other aspects of your database handling.

How to start creating a php script, that will be installed on many servers?

I was wondering how to start coding a script using php, and that script will be used on many websites.
so should I start first by creating the database ? and then start creating php files that will process data from the database ?
and should I start thinking of an install wizard for this script at first, or later when I finish the project I'll create one ?
I'm really confused on how to start a project, can you please give me some advice ?
and thanks everyone :D
should I start first by creating the database?
If you are going to use a database in your PHP script, then yes, you should install a database first. MySQL is a good start.
and then start creating php files that will process data from the database?
I would start on one server first, and create one PHP file called index.php that will do a database query. Then work your way to multiple PHP files from there.
and should I start thinking of an install wizard for this script at first, or later when I finish the project I'll create one.
Installing PHP files is 90% of the times as simple as just copying them onto your new server. I wouldn't worry about an install wizard just yet.
Another general tip because you are a beginner: install WAMPServer, it is a webserver/PHP server/MySQL Server in one that runs on your local computer. This is great for developing because you can just put your PHP files in C:\WAMP, edit them and directly see the result in your browser through http://localhost/. Then when you are happy you can upload to the server, or multiple servers. (Just by copying).
Most php software does not have, or need for that matter, what you would call an install wizzard.
I would suggest you to develop whichever way feels most natural to you.
Some people find it easier to start with the database design, while others prefer to write some code first and then expand the db schema further. There really is no right way to do it.
Starting a PHP project can be as easy as creating a text file and pumping out lines of code, however if you plan on creating a sizeable project, I would suggest a fully featured IDE.
Decide what dependencies your script has.
Decide which minimum version of PHP the script will be compatible with.
Work out a script which queries the users setup to detect whether these conditions are met or not. (eg does it rely on the mysql extension to be installed).
Detail how to meet each of the dependencies in case they are missing.
Explain which is the minimum version number supported, if your script detects it is below that version number.
Test it on your target Operating Systems.
Run a script which creates a database, test whether that was created. Provide detailed instructions on how to do this manually, and how to provide the correct privileges.
If necessary give them a config file which permits them to enter key information such as doc_root etc.
Conform to common wisdom such as short_tags = off else override these settings. Imagine the user is on shared hosting and is running on safe_mode = on.
Try and follow your own instructions and re-install it on your localhost, then on a live server - ideally on a variety of OSs too.

How do I setup Symfony to create multiple database schemas?

In my project I have 2 databases. propel-build-model is already set up to work for 2 databases - Multiple databases support in Symfony
If I make changes to either of the databases, I need the propel-build-schema command to rebuild the schemas for both.
I know I can do this manually by amending my settings per schema, but is it possible to create both at the same time? If so, how can I adjust my propel.ini file to have both connections?
I am currently using Symfony 1.0
The propel-build-schema command uses the settings in the propel.ini file which can store the configuration of a single connection only. However, you can probably do what you want by creating a copy of your propel.ini file with a different name to store the settings of your other connection and writing a simple shell script to rename the .ini files to propel.ini as needed and invoke propel-build-schema twice so that each invocation uses the right propel.ini (your script may also need to rename the output schema.yml files as well). Should be simple to do. Then, whenever you want the schema files regenerated, just run the script.

Categories