Regarding Symfony Documentation, when running a command, i can acess in real-time to each console output, no problem.
While collecting these informations in a controller, i want to render them in a view, one after an other.
What concept should I look for to achieve this ?
I dont think you fully grasp how the controller Request / Response paradigm works. A single request comes in, then a single response is given. There are ways to accomplish what you want but its involved.
High overview would be something like:
Have the output of the command logged to a file
Setup a route and controller action that takes a starting line number as an argument
The method reads the file and returns all new lines since then.
On the front end of the site setup some sort of polling AJAX request that requests the new route and passes the last line number its received.
Related
I have a application in which I can generate raw export in xls.
The problem is that the xls generation can be very long, more than the timeout duration.
I've checked and my query isn't the culprit (takes <2s for a regular query), but the xls generation is very long (for several thousand lines, I put different colors in cells, conditionally display data...).
I was thinking about the command, which runs in CLI, without timeout problem.
I can't use it directly, because the data to be generated has to be called by users (without cli access).
So I thought about calling the command in my controller
The user would choose the parameters in a form, send the form, and then in the controller, the parameters would be passed to the command that would do the heavy lifting.
My question is: In this case, is the command called in the CLI context (with CLI timeout = 0) or is it called in the application (Web) context (with timeout <50s) ? In the latter case, this would be useless, and I would be grateful for any advice on any alternate method to resolve my problem.
This is a textbook case for a message queue.
RabbitMq is recommended, and easy to use with Symfony.
You will have a producer, which will generate a message and put it in a queue. This will be done in your controller.
The db query and the sheet generation should be placed in the consumer (the command running in the background, picking messages from the queue and processing them).
When the sheet is ready, save it as a file, and perhaps log it in the database with a unique ID.
This migth sound difficult, but it is very simple, and you should learn it anyway :)
A problem is showing the result to the user. The simplest way is to refresh the browser every X seconds. Other choices include polling with ajax, and websocket based notifications from the server.
I've read online that you shouldn't update your database with GET requests for the following reasons:
GET request is idempotent and safe
violates HTTP spec
should always read data from a server-database
Let's say that we have build a URL Shortener service. When someone clicks on the link or paste it at the browser's address bar it will be a GET request.
So, if I want to update, on my database, the stats of a shortened link every time it's been clicked, how can I do this if GET requests are idempotent?
The only way I can think of is by calling a PUT request inside the server's side code that handles the GET request.
Is this a good practice or is there a better way to do this?
It seems as you're mixing up a few things here.
While you shouldn't use GET requests to transfer sensitive data (as it is shown in the request URL and most likely logged somewhere in between), there is nothing wrong with using them in your use case. You are only updating a variable serverside.
Just keep in mind that the request parameter are stored in the URL when using GET requests and you should be ok.
steps followed by me:
create Thread Group->http request default
added recording controller in thread group
added view result tree
After that-
WorkBench-
HTTP proxy server
Added listener-View result tree
I recorded the script
but I want to know how I correlate the all pages or flow so I got actual result
Like from
login(get)-Login(post) then
Calculte something in another page
then click on continue button and we got new page
and fill the details and again click on continue button the some thing save in database
After that redirect to payment gateway and after that we got final result
So please let me explain ho to do load testing for this flow
I believe that you need to go trough the following articles:
Correlation in JMeter in general
ASP.NET Login Testing with JMeter in particular
The whole idea is
To make first HTTP request to the very first page
Extract dynamic parameters and save them into JMeter Variables via one of the following PostProcessors:
Regular Expression Extractor
CSS/JQuery Extractor
XPath Extractor
Populate second HTTP Request using JMeter Variables from step 2
If you need to go further repeat steps 1-3 for 2nd request
This probably could not possibly be a more basic HTTP question, but I am very new to web development and I do not even know the right question to ask (evidenced by the fact that googling has not helped).
What I have: an AWS server with an Elastic Beanstalk environment set up. I have successfully compiled, uploaded, and run a simple "Hello World" program to the environment using Eclipse.
What I want to do: pass the server a number via HTTP request and have the server give me back an HTTP response containing the square of that number. On the back end, I want a simple Java class to do the squaring. (Of course, the goal is to be able to pass more complicated data to the server and have more sophisticated Java code on the back end for processing.)
What I think I need to do: create a Java Servlet to listen for and process the request. I think (hope) the documentation is good enough that I can figure out the HTTPServlet API, but I can't answer a more basic question: how do you pass an HTTP request containing some elementary data, like a number?
Thanks in advance!
You need to either GET, or POST (or PUT) your data. GET provides the data in the URL of the request, and will be displayed in the browser's address bar. POST data is provided as a separate request body.
http://www.w3schools.com/tags/ref_httpmethods.asp
A simple GET would look like this:
http://example.com/server?number=4
You can make a POST using a browser extension such as PostMan:
https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en
Or you can do it from the command line using curl:
curl -X POST http://example.com/server -d'data'
Once the data is more complicated than a few variables, you probably want to use POST rather than GET. Also, you can start to think about what your requests are doing. GETs should only retrieve data from the server. If you modify or create data, then POST (or PUT) requests are the methods to use.
As your server becomes more complex, you probably want to start reading about REST.
http://en.wikipedia.org/wiki/Representational_state_transfer
I'm currently using Spring MVC.
What I'm looking to do is have a web page where once the user submits a form, the controller writes a file to the output stream then flushes it, so the user may save the file. But I would then like the contoller to return a modelview, taking the user to another page.
At the moment once the output stream has been flushed, when the modelview get's returned, I end up with a "getOutputStream() has already been called for this response" error. (Normally I would return null after flushing the output stream to avoid this error).
So what I'm asking is, is there a way I can flush the output stream so the user can download the file and then return a modelview so the user is taken to another page?
Cheers.
I don't think what you're looking for is exactly possible, no matter what web framework you use. Best alternative I can think of is doing it the way Sourceforge.net processes downloads, e.g. a page with 'your download will start shortly', here's an example. (click the download link on the page)
You definitely can't redirect to a 2nd page if you've already begun writing to the output stream; this is part of the servlet spec rather than any one MVC framework