MongoDB connectivity with PHP dropping after idle time - php

I'm building a webapp with MongoDB/PHP, and everything's going great... except one thing.
My database connection is flaky. After X amount of time, when I refresh the page I get errors because queries are failing. I check mongod.exe and what I see is "Connection accepted from 127.0.0.1" - then I go back, refresh again, and everything's running all well and good.
What could be causing this? Database connectivity issues are something I never had to deal with in MySQL - but that's a whole different beast.

I would highly recommend you do your development with mongodb in a unix environment as they update the code the most often and you won't have to worry about strange bugs. Long ago i decided that doing dev in windows was much too inconvenient and moved my work environment to linux. If this sounds daunting, you might look into running a virtual machine with a local mount via samba such that you can run directly on a linux server on your local machine. Then you will have an environment similar to your production env. Hope this is helpful.

Related

Slow queries between servers

Good morning to everybody, I would like to ask about a problem I have and which I'm not able to solve it.
I have two servers, one is the web server (it contains a large web application) and the other one is the BD server.
The problem is that both are virtualized in a physical server with VMWare and they were running correctly until two weeks ago. In the start of this month we noticed that the web application ran very slow and we started to investigate what was the problem. We have tried a lot of things and we do not know what is the problem and, of course, how to solve it.
Both servers has an internal IP and only web server is accessible from Internet. Only web server access to BD server in order to get the results of queries. It's true that web server and BD server has an older versions of PHP and MySQL respectively.
We did the following tests:
Analyze the consumption of both servers. They are in 1% of memory, swap and al types of consumptions. Our physicial server is new from a year ago and both virtual servers does not use more than 5% of their resources.
Reboot both servers
Reboot physical server (VMWare server)
Restore a backup from 1 and 2 months ago of both servers to discard code and BD data errors
Review code (we do not touch code from before the error)
We did some queries from terminal's webserver and they were fast. We looked for the BD log and we could see that queries have been doing one by one in a "slow" velocity (0,5s for query aprox, depending on the query it can be more than a second).
We suspect that PHP is doing something bad, but we do not touch the code and we do not update PHP version or MySQL version. We want to try to update MySQL version in a new virtual machine and migrate all the data there, but we think it will not solve the problem.
The connection between servers is perfect and we think that layer 2 should not be the problem. In the same webserver we have another web application (Moodle) that connects to this BD server too, and it does not have this problem...
What can be the problem? It's very strange this change of behaviour of the web application. We were on holidays on August and we returned and we found this problem.
For more information we use PHP 5.6.40 (webserver) and MySQL Ver 14.14 Distrib 5.1.60, readline 5.1 (BD server). (yes, we know they are old versions but the web application and BD are old too)
I hope someone can help us, we are a little bit lost.
Thanks for your help!
I'd try updating your servers for one, issues like these are commonly caused by older software.
I'd also start logging or looking into loads so you can determine whatever causes the slow speeds you're getting.

How to troubleshoot performance difference between 2 web servers?

I have a production virtual web server that is being migrated to a new virtual web server on the same local network. The problem is that there is a performance problem on the new server.
For example, there is one page that loads in about 1 second on the original server, but takes over 25 seconds to load on the new one. I have already ruled out the database connection as the problem.
Both servers are Ubuntu Apache servers running PHP. There are slight differences in the versions of the servers, I will list as best I can here.
My main question is: is there a general way to profile the web requests on each server?
Similar to the way I can profile a python script or function and get a break-down of which parts of the program take the most time, I would like to profile the web requests on one server compared to the other.
Of course a web requests to the server are fundamentally different than programs run on a local computer, but I need to find where the bottleneck is. Any help is greatly appreciated.
Old Server Config
Ubuntu 14.04 - PHP version 5.5.9
New Server Config
Ubuntu 16.04 - PHP version 5.6.31 (also tested with version 7, same result)
I would suggest to log PHP script execution time.
If it comes from somewhere in the PHP execution, you will notice it easily.
Do a log at the start and one at the end. Then you can stress test both and see different execution time.
I seriously doubt the problem comes from PHP but if you do that you could also see differences with PHP7 which should be 30% faster.

My site is based on Symfony 1.4 and often crashes/goes down

It works properly, and after some minutes it just goes down... timeout, or no response. After some time it lives again. I don't do any special things, just testing. Has anybody met this situation?
are you running it locally? if so.. check your apache or IIS or whatever server you're using.
EDIT
For it to run local download
xampp
Check if you get the same problems

The right way? Automated Synchronization between 2 mysql DB

I already read a few threads here and I also went through the MySQL Replication Documentation (incl. Cluster Replication), but I think it's not what I really want and propably too complicated, too.
I got a local and a remote DB that might get both accessed/manipulated by 2 different persons at the same time. What I'd like to do is to sync them as soon as possible (means instantly or as soon the local machine goes online). Both DB's only get manipulated from my own PHP Scripts.
My approach is the following:
If local machine is online:
Let my PHP Script on the loal machine always send the SQL Query to the remote DB too
Let my PHP Script on the remote machine always store its queries and...
...let the local machine ask the remote DB every x minutes for new queries and apply them locally.
If local machine is offline:
Do step 2. also for both machines and send the stored queries to the remote DB as soon as
local machine goes online again. Also pull the queries from the remote machine for sure.
My questions are:
Did I just misunderstand Replication or am I right that my way would be easier in my case? Or is there any other good solution for what I'm trying to accomplish?
Any idea how I could check whether my local machine is online/offline? I guess I'd have to use JavaScript, but I don't know how. The browser/my script would always be running on the local machine.
What you're describing is master-master or multi-master replication. There are plenty of tutorials on how to set this up across the web. Definitely do your research before putting a solution like this into production as replication in MySQL isn't exactly elegant -- you need to know how to recover if (when?) something goes wrong.

Connecting to SQL Server very slow

I have a standard php app that uses SQL Server as the back-end database. There is a serious delay in response for each page I access. This is my development server, so its not an issue with the live setup, but it is really annoying for working on the system.
I have a 5 - 8 second delay on each page.
I am running SqlServer 2000 Developer Edition on a Virtual Machine (Virtual PC).
I have installed SqlServer on my development machine but get the same delay.
I have isolated the issue to the call to mssql_connect (calling mssql_pconnect has no effect)
It is a networking issue on how I have set up (or not set up, since I didn't really change default config) SQL server. It's not a strictly a programming issue but I thought I might get some valuable feedback here.
Can anyone tell me if there is a trick, specific set of protocols, registry setting, something that will kill this delay?
I was also experiencing a 5-10 second delay on every connect, using the official Microsoft SQL drivers for PHP (as suggested by #gaRex) - none of the answers posted here solved it for me.
As suggested by #ircmaxell, my problem was a DNS issue - and the solution was to edit the \windows\system32\drivers\etc\hosts file (your local local host file) and add the name of my own machine to it.
In the "system properties" dialog, find the "computer name" of your machine - then add a line like 127.0.0.1 my-computer to your local host file.
For me, the delay occurred once more, on the following attempt to load the page - after that, it was super fast, no delay at all.
Note that this problem may occur even on a physical machine, not only on a VM.
I came across network issues when running virtual pc, everything network related is slow, try adding this entry on your registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
Create new DWORD value named DisableTaskOffload and set its value to 1.
Restart the computer.
It worked for me, source.
Is it perhaps a DNS issue? I know that MySQL does a reverse DNS lookup on each login (not each connection). If you don't have a reverse dns record for your server (or your dns is slow) it can cause a major delay at login. There's an option in MySQL to disable that. I'm not sure about SQL Server, but I'd assume it may be doing something similar...
I remember the same problem, but forgot, how we have solve it.
To clarify please specify exact connect strings, your SQLserver versions and also try to start this old good utility c:\WINDOWS\system32\cliconfg.exe, which is also can bring some light.
Yes, I know, it's from 2k, but guys at m$ don't like to create client tools from scratch.
Also try to get "right" mssql client dlls for PHP.

Categories