MySQL AES_ENCRYPTION Slowing Down Performance - php

I'm hosting a port forwarded server on my computer. For a school assignment, I am trying to make a login page on my computer.
I set up my database and PHP script to validate my passwords and everything using AES_ENCRYPT() and AES_DECRYPT().
In Chrome, I launched the actual PHP script on localhost and the response performance I got for validating some sample data was excellent (the table has barely five rows right now).
However, in the actual site, I need to access this script using an AJAX request. As soon as I submit the request, the website freezes, and I have to close out the tab and try all over again (the tab doesn't refresh).
Why is this happening? I am using the POST method to send my data.

Related

Issues with PHP cURL between servers, return transfer probably wont catch the response

I have a really weird behavior going on.
I'm hosting a tracking software for users, that mainly logs mobile traffic. Now, the path is as follows:
1. My client gets a php code snippet to put in his website.
2. This code sends a cURL post (based on predefined post fields like: visiotr IP, useragent, host etc) to my server.
3. my server logs the data, and decide what the risk level is.
4. it then responds the client server about the status. That is, it sends "true" or "false" back to the client server.
5. client server gets that r
esponse, and decides what to do (load diffrent HTML content, redirect, block the visitor etc).
The problem I'm facing is, for some reason, all the requests made from my client's server to my server, are recorded and stored in the a log file, but my clients report of click loss as if my server sends back the response, but their server fails to receive those responses or something.
I may note that, there are tons of requests every minute from different clients' servers, and from each client himself.
Could the reason be related to the CURL_RETURNTRANSFER not getting any response ? or, maybe the problem is cURL overload ?
I really have no idea. My server is pretty fast, and uses only 10% of its sources.
Thanks in advance for your thoughts.
You touched very problematic domain - high load servers, you problem can be in so many places, so you will have to really spend time to fix it, or at least partially fix.
First of all, you should understand what is really going on, check out this simplified scheme:
Client's php code tries to open connection to your server, to do this it sends some data via network to your server
Your server (I suppose apache) tries to accept it, if it has resources - check max connections properties in apache config
If server can accept connection it tries to create new thread (or use one from thread pool)
After thread is started, it runs your php script
Your php script do some work, connecto to db and sends response back via network
Client waits till the answer from p5 or closes connection because of timeout
So, at each point you can have bottleneck:
Network bandwidth
Max opened connections
Thread pool size
Script execution time
Max database connections, table locks, io wait times
Clients timeouts
And it is not a full list of possible places where problem can occur and finally lead to empty curl response.
From the very start I suggest you to add logging to both PHP codes (clients and servers) and store all curl_error problems in some text file, at least you will see what problems occur often.

Communicating between HTTP user sessions on the same server - php wait for mysql field update?

I have a collaborative website where I need different sessions from different users to talk to each other (all sessions run php scripts on the same server). I was thinking of updating a "status" field in the mysql database and having other sessions from other users probing this field every second (using php).
Is there any potential issue with using such an approach (database caching etc...).
Is there a better solution?
thank you
Unless you want to have your users' browsers reload the entire page each second, you should use something like ajax to poll the server.
For the states, you could have your server update a json file that your clients can download periodically.
For inter-session communication, you could have a system with a message queue whereby messages are either transmitted specifically to a particular user or broadcast to all.
A user leaves a message with the server,
The server stores the message
transmits it the next time a the recipient's ajax call checks in.

Trying to display live data from Telnet connection

I've searched for a couple days I haven't found a solution for my problem.
I need to have a script connect to a telnet server send data to log in then display the output in a web page as the server sends is until the user leaves the page.
My experience is basic programing in PHP and Perl, but I'm willing to try others.
My initial thought is to write daemon script that connects to the server then repeats the data to the web clients via it's own server. Then when a user loads the web page a client connects to the daemon script.
Then telnet server only allows 1 connection from a specific user at a time that's why I'm thinking of the "Repeater" Server.
I'd like to have the data scroll up as it comes in. The data rate varies from several lines a second to minutes between lines depending on what's going on.
Can any one point me in the right direction?
There are several web-ssh-clients, one is with python on the server side and ajax in the browser. Maybe you can take this as an example. See http://antony.lesuisse.org/software/ajaxterm/

How to automatically reflect the new Updates (on Database) to User Pages

I am trying to create a new Notice Alert using PHP and Javascript. Suppose that a 100 users are currently logged into to the Online Notice Board Application and any One user posts a new notice. I want an immediate alert signal on all the users screen.
I know, that the simplest way of doing it is to constantly Ping the server but I don't want to do it as it will slow down the server.
Moreover, I am on a shared host. So I don't have access to any Socket Port. That means, I cannot establish any direct Socket Communication Channel from the Server to the User Machine.
Can any one suggest me some other solution to this kind of problems???
This is a COMET application. Google for COMET and you should find lots of information. Basically there are two techniques for retrieving asynchronous notifications over HTTP. The first is to ping the server, which you've already said you don't want to do. The other technique is to send a request to the server and have the server respond only when there is some data. In other words, instead of pinging once a second and only getting a message after 50 pings and 50 seconds, the server simply holds the first request for 50 seconds, until there is something to send, then responds. There are tools that will do all this for you.

PHP Jabber: if I login and check messages and disconnect, on the other users end I will show up as disconnected

Am not sure if what I am doing is absolutely correct. But here goes:
User logins into chat via web-based interface
User is informed of updates via Comet
User enters details which goto a PHP file which further connects to a Jabber server
Now the problem is that when the user wants to send a message, it's simple, run php in which i connect to jabber server and send the message. The problem arises when I am waiting for a message. Cause if I login and check messages and disconnect, on the other users end I will show up as disconnected.
Am I approaching this problem in a wrong way? Should I directly connect to the Jabber server (via javascript) instead of a PHP layer in between? How to recieve messages via PHP?
I haven't tried it out, but you might want to look at xmpphp. Secondly, you might want to consider keeping the user logged in to the XMPP server (aka a Jabber server) for as long as they're logged in to your website. You probably want to have a timeout of some kind in case they leave your website and don't come back.
As for whether or not you should connect via JavaScript, I don't see why you couldn't. I would suggest that you go for whatever seems the simplest to you. You might want to check out Strophe, which I hear good things about, for that case.
The only XMPP library that I've used extensively though is headstock, but that requires using python and Kamaelia.
this is an inherent problem (or feature) with http - there are no lasting connections (not really). you need a workaround, there is no real solution.
you could do it with java or flash, but that's not really nice (javascript 4tw!).
the other possibility would be to create an intermediate client what translates connections between the browser and the webserver to connections between the webserver and the jabber server. messy, but possible.
or maybe there is an API that helps with this.
directly connecting to the jabber server via javascript
i possibly slept through the latest ajax-inventions, but afaik you can only communicate with the host the source-html file comes from (ignoring greasmonkey and addons). no different domains, no different ports, period. unless you're going to teach your jabber server how to serve your chatpage-html to the browser, this will get problematic. moreover, staying connected doesn't even work, because that would require multipart-responses. those are only supported by mozilla, and this is why the ugly duckling COMET even exists in the first place. comet itself is a workaround to avoid the inability to hold connections while transfering data.
So the issue, as far as I can tell, is that when the Jabber user on the other end responds. The problem there, at least in part, is that the user is responding to another user on the Jabber server, yet you want the php script to be aware that this response has taken place without holding the connection open (which makes sense since the script is no longer running, probably).
One option, albeit a really silly one, is:
Have a php script that can broker a connection to the Jabber server for both sending and receiving for the user on your page,
Use AJAX to send messages for the user (the AJAX would point to the above script, the script would send the message.)
Have a Javascript infinite loop that pings the same script ever 10 seconds or so, checking in to see if there are messages. If there are, they get passed back to the client and output to the user.
There are only two issues with the above:
1) If the user isn't connected when the message is transmitted, will the php script still see/get the message?
2) A client side loop that makes ajax requests every 3 seconds would probably be a huge drain.
Solution 2:
OpenFire jabber server. It comes with a web chat client built in, and it has an addon called Fastpath, which is meant to handle HTML-based chats on the client end (like the "chat with an agent now!" feature on too many support pages.)
We use this at work and it is very customizable, can be integrated with other scripts (for instance, if you want a script that fills in the user details from their login, or adds some custom avatar, or whatever), and it (OpenFire) has tons of other extensions and addons that, if this isn't what you want, they probably have what you are looking for.

Categories