Lag in Ajax response - codeigniter

I am sending an ajax request to a controller/action in Codeigniter and it does some manipulation and sends a response.
The response that I get is accurate but the time taken for it to send the response is 4-5 seconds which is huge.
I was able to debug and pin point the cause of this lag. At the end of the method I am sending a mail. I am using mail() function here. I am even suppressing the error by writing #mail(), so on localhost it is not giving any error and executes well on the live server.
But even though there is no error, there is lag in both the environment i.e. locally and on Live server. I am not sure what the problem is.
Now as soon as I remove/comment out the mail() function, the response is instantaneous and lightning quick.
Please let me know what might be the issue what might be the possible solution.
Thanks in advance.

PHP mail() is very limited. Try using the code igniter Email class: http://codeigniter.com/user_guide/libraries/email.html

Related

ColdFusion API and Websockets

I am hoping someone can point me in the right direction. I have a CF2021 Server which uses a Node.js websocket server and CF pages (via javascript) as a client. Messages from user to user work as expected, so no issue there.
This CF Server also has a custom API built using CFML that handles and routes inbound SMS messages. My question is; what would be the best way to send the SMS message (by now its json) to the Node.js websocket to it can send it to the user(s).
I tried using the same javascript that the browser client uses, but it appears that the CFML API script is "browser-less", so that doesn't work, or should it?
I thought something like Apache Groovy may be the solution, but I am having difficulties with any websocket example I have found.
Any suggestions would be greatly appreciated.
thanks in advance
Flow matters.
If you want to handle an incoming message by delivering it to all currently logged in users who are subscribed to messages of the current sort: set up your message handler to deliver using lucee/adobe-coldfusion websockets. Be forewarned, Lucee takes some setup time, but once running, it is a great solution.
If you don't need immediate delivery, or you need a super simple solution: I actually have had some success with "Long Polling" you just have to remember to use "flush" early in the request, before any pause/sleep, then loop your message lookup requests for new data, with a 1-5 second delay between each loop. Once new data is found, I like to return the request to the client, close that polling request and start a new polling request using the client side. I typically won't poll for more than 60 seconds. Even if the returned json object is empty.

Why sending postman GET request slower than accessing the same endpoint in browser?

Basically the title. With postman, sending an API get response takes about 32 seconds, however, sending the same request using a browser with debugbar is way much faster which takes only 3 seconds. Can you please enlighten me I might be doing something wrong here?

AJAX Methods for Dyanmically Updating Webpage

I have a requirement to issue a continuous ping from a webserver, and send/display each result (success/fail) to the webbrowser.
However this raised the questions :
What is the best method for sending multiple responses back to the
client after a single (AJAX) request ?
How would you send a "stop sequence" back to the server to stop the ping.
Ive seen some articles around comment, long polling AJAX etc but would just like some clarification on the correct path to choose.
Thanks,

Sending tracking http requests

I am trying to take advantage of the tracking features supplied by vast. On each quartile I am sending an AJAX request (I have tried get, head, and post) to the url provided within VAST XML but every time I get 405'd.
Thank you!
Can you provide one of the quartile URLs so we can trace it?
What happens when you call that quartile directly in the browser, does it work outside of your Ajax call?
Are your other events working fine? such as impression, start play, click, etc..
From the HTTP methods you tried GET should work, but POST should not be used with the VAST trackers. Hopefully the server you are hitting is not giving you an incorrect error code, masking an internal error.

Sending POST data via javascript to a PHP safely

I'm trying to work around the fact that twitter uses a call-limit by letting the client do a call to Twitter(By parameters given by my script, like last_id, username etc) and give me the newly found tweets by posting them via an AJAX request that I store in my database after.
However, if i figure out the parameters that are being sent from my getTweets javascript function to my save_tweets.php via a JSON array it's not that hard to post random stuff with an extension like the REST console in chrome.
Obviously i want the tweets to be legit and can not be manipulated(or posted) by anyone. I understand that javascript is clientside and therefore there is not much control over the content being grabbed and put away again but is there a way to be safe that the POST data you send comes from a user/webpage that is allowed to do so?
I've tried thinking of a PHP session token or something, but that doesn't fly since you have to cross-check that token which you therefore have to send along with the JSON array to my PHP.
Thanks in advance,
p.s If you know a different way to not being obstructed by a call limit to Twitter i'd be happy with that too. But 150 calls from a server isn't that much if you get a 1000+ users an hour to your page.

Resources