Starting a remote MySQL server using php - php

I currently use a VPS hosting MySQL to help reduce the load of my main server. Occasionally the SQL server conks out due to the amount of traffic it receives.
I'd like a small PHP script that will start the remote server. I already have a way of detecting when the SQL server isn't available, I just need a way of executing /etc/init.d/mysql start.

Have a look at the rexec command

Related

Can PHP trigger an event on a remote Windows Server

Is there a way for PHP to send a signal to a Windows Server to run a script?
I am writing a web application which generates database entries that are later synced by a program on a remote Windows Server. PHP & mySQL are running on AWS.
The application on the windows server syncs the mySql database with Quickbooks. Ideally I would like to send a signal from PHP so that if PHP has updated the database, letting the remote Windows server know which script to run to in order to initiate the sync program. I would need to be pointed in the right direction both on the PHP commands as well as how to setup the listening service on Windows.
I was thinking if I could get Windows to listen on a specific port for a short XML file, PHP could send a password and entity ID number to identify which script to run.
Any suggestions?
Thanks!
You can use php on both end. Just install php server on windows, then when request happened execute a windows command. Php can do that.
I would schedule a task to read a specific file from the windows server side and from the php side you could use cron jobs. This question is too broad though and there are several approaches to that. You need to be more "code" specific.

Advantage and PHP - Error 6303: Maximum Advantage Database Server connections exceeded

My company php web site is connected to an Advantage Database Server where are stored all necessary data such as users, passwords and customer registry.
Lately we started to get an error requesting web pages:
Warning: SQL error: [Extended Systems][Advantage SQL][ASA] Error 6303: Maximum Advantage Database Server connections exceeded. axServerConnect, SQL state HY000 in SQLDriverConnect in C:\...\www\... on line...
It's becoming critical day by day and it can happen once a week or twice a day without an apparent reason.
When website crashes, database service still working great with other applications connected and the only way to restore web service is to restart apache web server.
On database server we've got ads.ini configuration file in C:\Windows folder where we raised max connections setting with "MAX_CONNECTIONS=1000" which is really big compared to our needs.
Can it be useful if we set also "RETRY_ADS_CONNECTS = 1" ??
I found this post where R&D confirms a bug in may 2009:
Is this a bug with Advantage Database?
Has this been fixed? In wich release?
Where can i see the real number of connections open by apache on db?
Each php page closes ads connection on footer, what can cause connections to exceed??
Thanks in advance for help.
-
ENVIRONMENT INFO
Database:
Advantage Database Server 10.10.0.6 on Windows 2003 server
Web server:
Apache/2.0.59 (Win32) mod_ssl/2.0.59 OpenSSL/0.9.8d PHP/4.4.7 on Windows XP pro
On phpinfo() page we get "Advantage Version" "8.00.0.0".
Why this? Do we need to upgrade php-advantage extension?
Lots of questions, but I will try and address each.
1) 6303 Error. Using MAX_CONNECTIONS is the correct way to resolve this.
Make sure MAX_CONNECTIONS is in the [SETTINGS] section
Check if Apache / PHP / ADS driver is using the correct ads.ini file. You can use Process Monitor from Sysinternals to see what ads.ini file was opened successfully. If you upgrade your PHP driver you can set an environment variable adsini_path to point to the directory where the ads.ini lives.
2) Setting RETRY_ADS_CONNECTS=1 will be helpful. This also goes under the [SETTINGS] section of the ads.ini. When an ADS client receives a networking error (generally a 6000 class error) then the error is cached by the client driver and subsequent attempts to connect will use the cached error vs. retrying. Setting RETRY_ADS_CONNECTS will tell the ADS client to ignore the cached error and retry the connection
3) Bug: Looks like this was fixed in 9.10.0.9 version of the driver based on the release notes on http://devzone.advantagedatabase.com.
Fixed an issue where the garbage collection reference count on a
connection would be incorrect if multiple SQL statements were opened
on it.
Since you are running a 10.1 server you may look at updating to a 10.1 client which will also contain the fix. 10.1 Advantage PHP Driver
4)See the real number of connection
I would recommend using the stored procedure sp_mgGetConnectedUsers, you can use ARC (Advantage Data Architect) but it can be difficult to group, order, etc.
Since you are using 10.1 you can include the results of the stored procedure in a query such as
SELECT COUNT(*) FROM (EXECUTE PROCEDURE sp_mgGetConnectedUsers()) u WHERE ADDRESS='xxx.xxx.xxx.xxx'
You could also use other fields to identify the PHP application such as UserName (the server name), DictionaryUser (assuming the php application uses a unique user), ApplicationID
5) PHPINFO shows Advantage Version of the Advantage PHP client driver. You may want to upgrade the client driver for reasons mentioned above. Should be as simple as swapping DLL files (ace32.dll, axces32.dll, adsodbc.dll and php_advantage.dll), but I would recommend testing first to ensure you get everything.

Connecting to external MySQL DB from a web server not running MySQL

While I've been working with MySQL for years, this is the first time I've run across this very newbie-esq issue. Due to a client demand, I must host their website files (PHP) on a IIS server that is not running MySQL (instead, they are running MSSQL). However, I have developed the site using a MySQL database which is located on an external host (Rackspace Cloud). Obviously, my mysql_connect function is now bombing because MySQL is not running on localhost.
Question: Is it even possible to hit an external MySQL database if localhost is not running MySQL?
Apologies for the rookie question, and many thanks in advance.
* To clarify, I know how to connect to a remote MySQL server, but it is the fact that my IIS web server is not running ANY form of MySQL (neither server nor client) that is giving me trouble. Put another way, phpinfo() does not return anything about MySQL. *
Yes, you can use a MySQL database that's not on the same machine as Apache+PHP.
Basically, you'll connect from PHP to MySQL via a network connection -- TCP-based, I suppose ; which means :
MySQL must be configured to listen to, and accept connections on the network interface
Which means configuring MySQL to do that
And given the required privileges to your MySQL user, so he can connect from a remote server
And PHP must be able to connect to the server hosting MySQL.
Note, though, that habing MySQL on a server that's far away might not be great for performances : each SQL query will have to go through the network, and this could take some time...
If phpinfo is not returning anything about MySQL you need to install the MySQL plugin for PHP, easiest way to do that probably is to just upgrade PHP to the latest version. If not there is a .DLL file that you will need.
http://www.php.net/manual/en/mysql.installation.php
you will need to install the mysql extensions. this link should help: http://php.net/manual/en/install.windows.extensions.php
The MySQL server has nothing to do with PHP itself. What "mysql support" in PHP means is that it's been compiled with (or has a module loaded) that implements the MySQL client interface. For windows, it'd be 'mysql.dll', and on Unix-ish systems it'd be 'mysql.so'. Once those are loaded, then the various MySQL intefaces (mysql_xxx(), mysqli_xxx(), PDO, MDB2, etc...) will be able to access any MySQL server anywhere, as long as you have the proper connection string.

Bash or PHP script to execute stored procedure on SQL Server

I am trying to write a bash or PHP script that will execute a procedure on a MS-SQL Server. Does anybody have pointers on how to do that in the easiest and most convenient way?
The script will run on a separate Linux box.
Installing the php mssql drivers (on Linux) can become a real pain. Just take that in mind.
We had to deal with a hosting company, which refused to install them. I ended up with a wcf service (installed as a windows service) on the sql server machine, which just invokes the sp and a simple http request from the php script. I think it is quite cool actually.
I realize that a lot of people would qualify that as an absolute overkill, but there is no doubt that an http request can be performed from a lot of devices and platforms. You don't have to install the sql drivers on every machine and platform you need to execute the sp.
That way you don't have to 'open' the sql server for remote connections, but you host wcf service (which is not more secure or anything... just a difference, some people get crazy when hear about allowing sql remote connections)
you can use mssql class for PHP.
Here is an example of how to execute a sproc in PHP.

php quits connecting to Oracle

We've got an ongoing issue where php 5.2.6 will quit connecting to Oracle 10.2.0.4.0. We can go weeks without any issues and then (usually Saturday mornings) php will no longer be able to connect. The database is up and running and we can connect to it manually with varous DB tools but php won't ever connect again until we reboot the web server. The web server is running IIS 6.0.
We connect using $connection = oci_connect ($userID, $password, $TNS) where $TNS is the appropriare TNS in the local tnsnames.ora file. We go through a connection manager at our data center but I don't know the details on how that works.
One of the reasons this has been dogging us is that we're not really sure who is causing the problem and the various logs haven't shed any light on that. Is it a php issue as it would appear or is the DB itself for some reason rejecting the connections, or is it perhaps the connection manager? Some input in figuring that out would help a lot. Our load is lighter on weekends so that should be the issue. We haven't been able to find any outside processes that could be initiating the problem.
Not really a "root cause" solution, but if you're not using FastCGI, a switch to FastCGI might help with this issue. A PHP process in FastCGI does not live for "weeks". Since the oracle client is loaded dynamically into the PHP process, the automatic process restarts you get with FastCGI should be identical to a web server restart. You can always tweak the FastCGI settings to restart the process more or less often.
If you're using ISAPI, that probably is your root cause though. PHP and ISAPI are bad news when combined. Problems are almost inevitable.

Categories