I want to set up new project in Yii 2.0.6 framework, which I will use for simple REST calls only (making requests and getting responses from DB).
I have downloaded the framework from their official site (basic pack from Archive file). Now initially I have empty project that initially take place of ~24MB. I'm not sure if this is a good idea, because every time I will make some request (from mobile devices), it will probably load all these 24MB from the server. Is it how it works?
Is there a way for setting up the Yii 2.0.6 project with minimal size on the disk? I really need everything to be optimized and to load as minimal code as possible.
PHP files will only be rendered in the server side where only required files will be loaded and used and all what your mobile is going to receive are the Json outputs if what you are going to build is a REST api.
To check the size in byte of a json file that your mobile is going to receive, you can use curl as described in Yii2 REST docs and add grep Content-Length to the request :
curl -i -H "Accept:application/json" "http://YOUR_RESOURCES_URL" | grep Content-Length
or you can use the network tab of a navigator dev tools instead :
here the json file's size is 392B and it took 179 ms to receive it from server
Also remember that by default Yii is installed with dev environment settings, there is optimizations to do before publishing the product in order to optimize time responses. check this for more details.
It is also good practice to use a tool like gzip to compress data before sending to mobile as described here : JSON REST Service: Content-Encoding: gzip
Of course not. Yii only load the required classes (and files) on the fly, thanks to the autoloading mechanism.
A few components are preloaded during the bootstrap phase (and you can add or remove some of them in the configuration file). Other classes won't clutter your memory as long as you don't use them.
Related
I ran a test run for speed test of my page. It said "Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.".
My Page using Play Framework. Came across a lot of answers regarding .htaccess file but it is not supported in Play Framework. How to cache the static files on browser level?
When using Play in production mode, it already sets the ETag header, so whenever a browser requests a file matching that eTag, play just returns 304 Not Modified. This will save you data (the browser will not download the file again if it has the right version), but still requires a request to the server.
If you want to specify a expiracy date, you can use assets.defaultCache="max-age=3600" to your application.conf (adapt the value for your needs: 3600 is one hour in seconds).
I can't check this right now, but I think Play also sets Cache-Control: max-age=3600, so probably the warning you are getting is because this value is too low for the tool you are using to check the caching.
You can also set the expiracy time to individual assets (see https://www.playframework.com/documentation/2.5.x/AssetsOverview#Additional-Cache-Control-directive)
Note that you should only specify a high expiracy time to assets that you are sure that don't change a lot...
Our application is entirely built on websockets. We don't do any HTTP request-reply. However, we are stuck with file download. If i receive file content via websockets can I wrote to local folder on user computer ?
If it makes a difference, we are only supporting Chrome so not issue if it doesn't work on other browsers.
Also, I know i can do this via HTTP. Trying to avoid it and stick to websockets since thats how the entire app is.
Thanks a lot in advance!
The solution depends on size of your file.
If size is less than about 50 MB, I would encode file's content to base64 string on the server and send this string to the client. Client should receive parts of the string, concat them to single result, and store. After receiving whole string, add link (tag <a>) to your page with attribute href set to "data:<data_type>;base64,<base64_encoded_file_content>". <data_type> is a mime type of your file, for example "text/html" or "image/png". Suggest file name by adding download attribute set to name of file (doesn't work for Chrome on OS X).
Unfortunately I have no solution for large files. Currently there is only FileEntry API that allows to write files with JS, but according to documentation it is supported only by Chrome v13+, learn more here https://developer.mozilla.org/en-US/docs/Web/API/FileEntry.
I know how to use JSON in dart also communicating with a server using the HttpRequest API from the dart:html library and parsing JSON data using the dart:convert !!https://www.dartlang.org/articles/json-web-service/
I am looking for Dynamic content loading using Ajax asynchronous methods or calls in DART! ..
like .. the web page need to load content dynamically if there is any change or update in JSON files in server! ..
And how to do this in Angular Dart!?
There's no way to be notified when something changes on the server without either a) polling for changes (this can be pretty wasteful) or b) having the server notify you.
For (a), you could create a periodic timer that fetches the JSON or checks whether it's been updated (you'd need some way of checking this with the server).
A better fit would be something like Web Sockets, with the server able to push your JSON to the client whenever it changes. However, this is quite an architecture change from pulling JSON from the server, because you would need to be holding web sockets open between the server and all clients that have the page loaded, so the server can send the data to them all whenever it changes.
There are some samples of using Web Sockets on the Dart site; but bear in mind you'll need something on the server, this won't work if you only have access to the client.
I'm building an app with Three20 and I'm using the photo gallery component.
I can't find any documentation about the different cache policy available.
Could you explain to me each of them ?
TTURLRequestCachePolicyDefault
TTURLRequestCachePolicyDisk
TTURLRequestCachePolicyEtag
TTURLRequestCachePolicyLocal
TTURLRequestCachePolicyMemory
TTURLRequestCachePolicyNetwork
TTURLRequestCachePolicyNoCache
TTURLRequestCachePolicyNone
Thanks !
I'm not sure of the exact policy of each type, and they are not well documented. These is the information I have found out by using and reading the code:
TTURLRequestCachePolicyNone - requests will not use three20 cache system. meaning each request will perform a network request.
TTURLRequestCachePolicyMemory - the request will try to look for an existing cache object in the device memory. memory is cleaned each time the application is terminated. not sure how useful it is. from what i have seem, it's working only for UIImage objects
TTURLRequestCachePolicyDisk - Three20 saves cache objects in the application document folder as files. The request will look only on that disk cache.
TTURLRequestCachePolicyNetwork - not sure. i think it's checks the header expire date of the content.
TTURLRequestCachePolicyNoCache - will not cache new responses and will not look for cache objects in existing cache
TTURLRequestCachePolicyEtag - requests will be looked based on their header etag. I think it's a little buggy in three20, so it's better not to use it.
TTURLRequestCachePolicyLocal - requests will be looked on both disk & memory cache
TTURLRequestCachePolicyDefault - requests will be looked in all cache types (besides the etag)
From my experience, i use TTURLRequestCachePolicyDefault with expiration time i want, and TTURLRequestCachePolicyNoCache for requests i want to disable cache and make sure each request is doing a network call.
What is the best practice when serving files from the Zend Framework MVC? These files have to be served from the MVC as they are protected.
I know you can read in the file and place it into the Response object but this seems like a bad practice as you would be reading the entire file into memory then serving it. Right now I usually do:
header('Content-type: image/jpeg');
fpassthru(fopen($path, 'rb'));
exit;
But this also doesn't seem right as I'm stopping the execution of the script. Any suggestions?
I see nothing wrong with just exit(); What you will need to be careful of is any output buffering layers you may have on (gzip compression, etc). Large files could blow up those buffers pretty quick, so you'll want to close them out and potentially 'chunk' your output with a fopen/fread loop.
I would suggest building a super-simple script for retrieving files based on ticket system like in CMS you generate ticket to DB - filename, unique-hash and than redirect to the super-simple file-retieving script (file.php?hash=asd52ad3as1g5). It will get the hash from query and based on it fetch the real filename and push that to output as you have written using fpassthru. The hash need to be unique and hard to guess...
You could try using the X-Sendfile header. It is supported by lighttpd and newer versions of apache. Basically the webserver will replace the output of the script with the file you specified. The downside being that it is specific to the configuration of the webserver, so you may be on a host that doesn't support it.