I am using CodeIgniter for my API implementation. Please find the server resources and technologies used as follows :
SUMMARY
Framework : CodeIgniter
Database : MySQL (Hosted on RDS)
Hosting : AWS t2.Micro
Web Server : Nginx
I am using 2 Slaves and 1 master Database as per the following link
CodeIgniter configure different IP for READ and WRITE MySQL data
I am using the following in every controller for making a database connection.
$DB1_READ = $this->load->database('READ', TRUE);
$DB2_READ = $this->load->database('READ', TRUE);
$DB3_WRITE = $this->load->database('WRITE', TRUE);
I am also using different READ and WRITE connections in the Database.php file:
2 READ SERVERS and 1 WRITE SERVER (MASTER)
PROBLEM
As I am loading Database in my controllers, WHEN I am only calling my READ Database, it's making a WRITE Connection to the WRITE server.
Where should I call $this->load->database so that if I am only going to EXECUTE READ query from READ database then it should not go to WRITE server causing failure of the WRITE server.
It is opening an unwanted connection at WRITE which in turn increasing Load on My Master Database. As per AWS RDS , I can only have 1 Master , so that is a HUGE issue for me as my MASTER dies Every time.
Related
I have a hybrid app that runs with information from a database related to a portable server.
I need to retrieve information from my web server (different to the previous one) and I don't know how to do this.
I have a configuration file with the information and function to establish a database connection IN THE WEB SERVER.
What I'm trying to do is to include this config.php file into an app file to establish the connection from app server with web database.
I've tried cURL with no success.
So if i'm understanding you right you want to exchange the configuration of a database connection dynamically between two "hosts" ? Currently you are trying to download the config.php file via cURL ? This is not going to work, if you access the config.php via cURL it is processed by the webserver, so you probably get an empty response because the config.php has no output.
There are some solutions for this but I have serious security concerns. If you make your database configuration without any security measures available through a "webservice" this may result in very serious problems like dataleaks etc.
Please do not use the following in a production envorionment.
The keypoint is you have to build an array / object which holds all the data you need. Then you have to serialize it and transfer it to the second host.
A very simple and very insecure way to do this is to write a new script which can be reached through an GET request which responds with the serialized object. On the other host you simple unserialize the response and you have the object which contains your configurations.
The file you access from the remote host:
<?php
// Build your config array / object
$config["url"] = "your.database.host.com";
$config["port"] = "The port you use";
$config["other"] = "other stuff you want to transmit";
// serialize it and output it
echo serialize($config);
?>
Your remote host script:
<?php
// get the response with your config
$content = file_get_contents("<your host>");
// unserialisze it
$config = unserialize($content);
// database stuff
?>
I urge you not to transmit sensible information like this without a proper security concept. Maybe you could use ssh to copy the file or build a proper REST API with authentication and validation.
I would like to make a web interface in PHP to see the FreeSWITCH activities (calls, etc), possibly hosted on a different server than the one where FS is running.
I've seen the server status on the FS server using command line (php single_command.php status), but now I would like to see this status from another server.
When I try to copy ESL.php file to this remote server and try to check the status, I get this error message:
Fatal error: Call to undefined function new_ESLconnection() in
/var/www/freeswitch/ESL.php on line 127
This is my index.php file:
<?php
ini_set('display_errors', 1);
$password = "ClueCon";
$port = "8021";
$host = "192.168.2.12";
require_once('ESL.php');
set_time_limit(0); // Remove the PHP time limit of 30 seconds for completion due to loop watching events
// Connect to FreeSWITCH
$sock = new ESLconnection($host, $port, $password);
// We want all Events (probably will want to change this depending on your needs)
$sock->sendRecv("status");
// Grab Events until process is killed
while($sock->connected()){
$event = $sock->recvEvent();
print_r($event->serialize());
}
?>
I undestand that the webserver doesn't have FreeSWITCH installed, so the error message is obvious, but i don't see how to access to this information from this webserver.
Thank you for your help.
Depending upon your need you can use either Inbound or Outbound socket. I do not know much about PHP and FS Event Socket but yeah tried enough with python. I highly recommended to go through thislink.
So if you just want to do small task like initiating a call, bridging any two given number etc i think you should go with Inbound socket(making cli command from your web server to freeswitch server) or mod_xml_rpc.
And if you want to have full control of everything that happens on FS server like showing live call status and modifying their states or say a complete interactive telephony dashboard then you should go with Outbound socket.(Your FS server will send all events to your web server.)
However in your case problem is I think you did not properly build the php ESL module.
this link might help you installing ESL
Rather than using ESL, you might want to consider using the XMLRPC. The connection is very straight forward:
https://wiki.freeswitch.org/wiki/Freeswitch_XML-RPC
The credentials for the XMLRPC are in your autoloads_configs/xml_rpc.conf.xml
First of all let me say there are no CLEAR tutorials for how to do this on windows, I'm a programmer and have been using MySQL and PHP for years, and have never seen so many different answers when it comes to linux, and absolutely nothing for windows users.
Anyway I have been working for 2 weeks trying to solve this myself, and I am at the same place no matter what tutorial, method or whatever I try. Basically I have two MySQL Servers. One Master, and One Slave (setup through phpMyAdmin)
I have both servers online and they can see each other and are connected to each other, however when it comes to syncing under the Slave Status table in phpMyAdmin I am constantly getting errors saying tables don't exist. But they do. Now I'm not sure if I am supposed to completely import the databases from my master manually, and then it updates it or whatever (again no clear tutorials are out there for windows). Below is the table i copied from phpMyAdmin.
Slave_IO_State Waiting for master to send event
Master_Host XX.XX.XX.XX
Master_User XXXXXXXX
Master_Port 3306
Connect_Retry 60
Master_Log_File mysql-bin.000012
Read_Master_Log_Pos 1221
Relay_Log_File *servername*-relay-bin.000003
Relay_Log_Pos 253
Relay_Master_Log_File mysql-bin.000001
Slave_IO_Running Yes
Slave_SQL_Running No
Replicate_Do_DB
Replicate_Ignore_DB
Replicate_Do_Table
Replicate_Ignore_Table
Replicate_Wild_Do_Table
Replicate_Wild_Ignore_Table
Last_Errno 1146
Last_Error Error 'Table '*databasename*.*tablename*' doesn't exist' on query. Default database: '*databasename*'. Query: 'DELETE FROM *tablename* WHERE expires
Skip_Counter 0
Exec_Master_Log_Pos 107
Relay_Log_Space 211493
Until_Condition None
Until_Log_File
Until_Log_Pos 0
Master_SSL_Allowed No
Master_SSL_CA_File
Master_SSL_CA_Path
Master_SSL_Cert
Master_SSL_Cipher
Master_SSL_Key
Seconds_Behind_Master (blank but would like this setup)
I should also add that this database that supposedly has missing tables is working perfectly on the master for an active website.
Any help to point me in the right direction would be appreciated.
You want to take a full backup of the master database and load it onto your slave or manually copy them over while the master isn't doing work. When you run your CHANGE MASTER command on the slave before starting it you want to specify the first binary log file that was created after your backup was taken like this:
CHANGE MASTER TO MASTER_HOST='xx.xx.xx.xx', MASTER_PORT=3306, MASTER_USER='user', MASTER_PASSWORD='*secret*', MASTER_LOG_FILE='mysql-bin.004388', MASTER_LOG_POS = 0
The Seconds_Behind_Master will automatically show once the slave doesn't have an error.
That is all there is to it.
I have my website ready on the localhost and use doctrine 1.2 for the database, I want to upload the website to a web host to try it so I changed the parameters (Database, User, Password, Host) of the DNS in the config.php file, but I don't know how to build it since I used to run this command in the CMD:
php doctrine build-all-reload
and I can't use the exec() command or it's alternatives on a shared host.
I use PHP in my website.
So how can I build my database ?
If you have a yml file you can create a php script and run the following to create the db from your yml.
$options = array(
'packagesPrefix' => 'Plugin',
'baseClassName' => 'MyDoctrineRecord',
'suffix' => '.php'
);
Doctrine_Core::generateModelsFromYaml('/path/to/yaml', '/path/to/model', $options);
In general Doctrine_Core has a few methods to create, drop and insert to db after you have set up the connection. It is pretty straight forward.
Dump your database on localhost and load it on your webhost using whatever means you have available (phpMyAdmin for example)
Migrations will be worse.
I switched my mongodb environment from replication-sets to sharding with replication-sets through mongos.
I had 3 rep-sets (A,B,C) which I switched to S1(A,B); S2(C,D) with mongoS running on A,B,C,D.
When I was connecting to my old system, I connected as followed
new Mongo("mongodb://A,B,C", array("replicaSet" => "repset-name"));
Now I tried to to the same with mongoS wich throws an interal server error
new Mongo("mongodb://A,B,C,D", array("replicaSet" => "repset-name"));
If I get rid of the "replicaSet" option, it works again.
new Mongo("mongodb://A,B,C,D")
I was wondering if mongoS now balances the reads between the rep-sets in the shard (e.g. S1 balance between A and B) without the "replicaSet" option set?
By the way, pymongo reacts the same way with a pymongo.errors.AutoReconnect "No address associated with hostname".
Thx
Correct, once you've sharded, you should connect your driver to the mongos as if it were a single server. Mongos is now responsible for distributing reads and writes among the primaries and secondaries around your cluster. Set slaveOk to True for reads if you want mongos to distribute reads to secondaries.