Flex get extremely slow response some php script - php

I am fixing up a php script to recieve a byte64 encoded image and store it to database
Here is my problem the script takes very long time, sometimes up to 5 minutes, to respond when flash calls the script(via a post request)
(i test it with a very small image)
if i remove the byte64 encoded data from the request it loads fast, and if i call the script from the browser with no data it is fast
i tried removing all php script from the script file so no php is run, and with data it is still slow.
My guess is that this is somehow server related, but i have no clue what this could be, other than it must happen before php is run.
and i have no htaccess file on the site,

"if i remove the byte64 encoded data from the request it loads fast"
So you know exactly where you issue is at. Test the queries, if they're not optimizable, store your images the normal way.

i ended up rewriting the script to a normal upload and then store them as files, storing images in DB is bad mojo, but was trying to avoid having to rewrite the intire script at the time :)
but thanks for your time!

Related

#only server-side# How to get the echo-html-div-result of the php code saved to png-file on this server?

Like a Log-file is written by a php-script via fwrite($fp, ---HTML---),
I need to save an HTML DIV as png-file on the server.
The client-browser only start the php-script,
but without any client-interaction the png-file should be saved on the server.
Is there a way to do this?
All posts (over thousands) I have been reading are about html2canvas,
which is (as I understand) client-side operating.
I know the html-(html-div)-rendering normally does the browser.[=client-side]
But is there a way to do it in PHP on server-side ?
Reason:
Until now the procedure is
print the div via browser on paper twice
one for the costumer,
one to scan it in again to save it on the server as picture and throw it in the paperbasket.
By more than 500 times a day ...
By security reasons it need to be a saved picture on the server.

php/ajax uploader bar?getting data for upload bar

I am creating an upload interface to upload files in php.
Files are uploading fine.
But I want to give the user some feedback as how much time will it take to upload, how much of the uploading has been done etc..
I have found online code which gives ajax plugin to do what I want.
BUT my question is more fundamental, WHERE do I get the data in php that tells me how much of the file is received? what is the connection speed(connection speed and file size can be used to get time left) and other information needed?
can i get the data form php or am i looking at the wrong place?
Everything is in the documentation:
http://www.php.net/manual/en/session.upload-progress.php
WHERE do i get the data in php that tells me how much of the file is received
You don't. Uploading is handled by the webserver. When the upload is complete your PHP script will run and it gets a reference to the temp file(s) created by your webserver.
I think there are plugins or mods that do allow you to monitor theses processes. There is session.uploader-progress.php
but there is a much easier solution!
Use the JS FileReader API to slice the file into small chunks (like 5mb) then you can already make a pretty good loading bar. Additionally you can monitor the progress of XMLHTTPRequests to see how many bytes have been sent. This should get you a pretty spot on progress indicator.
This also alleviates common problems with exceeding max_upload_size.
An actual code solution is quite involved so I will refrain from posting one. You should be able to find samples or tutorials.

Is it possible to interrupt file upload in PHP (with APC)?

It is possible to track the upload status in PHP (with APC) and I'm wondering if I can cancel the transfer somehow from PHP. Is it possible?
Unfortunately, no. The upload is something which is triggered and controlled by the client (think about it — it is a part of the POST request). This means that even if the upload is going to a 404, it will still continue to upload until the server returns the response.
Maybe you could use JQuery "chunk" file uploaders, so the upload can be made by chunks (through JQuery) and the server can decide when to stop receiving. You'd have to modify the chunking plugin, I guess, but that shouldn't be too much of an effort.
It still doesn't offer you the possibility to cancel in the middle of a packet, but you could probably chunk in 1% bits and make sure you have plenty of opportunities to tell the JQuery script that you don't want more.
See https://github.com/blueimp/jQuery-File-Upload/wiki/Chunked-file-uploads

Need to execute a code in background

I have done a code to receive images from iphone to PHP Server and I need to resize these image and move to 4 folders.
Only then the json respose is giving to iphone. But it takes much time.
Requirement:
i want to move a file to the folder "folder1" then want to give the json response.
the resizing process should do from this "folder1" after giving json response.
How to run this resizing process in background.
Here is my code:
http://pastebin.com/qAcT1yi9
You could always send your php script to run in the background with a Linux command.
Example:
// using backticks to execute the Linux command but there are
// other alternatives
$cmd = `php runScriptInBackground.php &`;
echo $cmd;
First send/upload the images and send a response back, without doing the resize operation.
Then, if the upload was successful, let the browser issue another request and do the resizing. When this succeeds, send the message ‘resizing successful’ back.
A common solution to this problem is implementing a loading/processing message on hitting a specific event. Then - still being displayed - the action will continue to load on the background and the result page will finally be displayed when done.
Although the user must wait, I prefer this above display a result message when the actual result is not known. Unfortunately I'm not sure how this is done on iphone development.
if your building in objective c then you may just resize make a copy and resize it there and send the resized image to your php you could then display a spinner and json result back to the user and also if the is an error the user will still have the resized image to try again with... Also another thought I had was was to use push notification. I don't know what that code would look like but it's something to consider
you need some async javascript or an iframe in your page posting the image to your server and providing feedback to the user.
This means that the 'main' page would not change, but some visual information can be provided to the user.
You can display an animated gif loader or use JS setInterval to give the user the feeling that things are moving forward why waiting for the server to respond.
If the processing is split in more 1 parts, after each step the server could respond with an HTML page and a redirect: this would even work in an IFRAME without JS.
Each 'page' would perform one more step. But if the user closes the browser before all is done you would end with an unfinished task.
A DB, real background processing, and client side JS polling are a more robust alternative.
A full answer would be quite long and require way more details on your settings (apache CGI PHP? or mod_php? are you using an MVC model or framework, or are you writing a page-oriented website?).
If i had to write a full answer I would forget PHP and use Python and celery http://celeryproject.org/ ;-)
PS.
I just found out that a few related questions already existed:
PHP Background Processes
Asynchronous shell exec in PHP
You can do it realy in two times, first send de files and save on first server, after when the user request that you generate the necesary parts.
You will pass the costs from the file sender to the first request from that.

Ouput stuff while php script is running

So I just created a script to resize a whole bunch of images. Is there anyway to have there be output as its running through the loop?
Basically I have like 400 photos in photo db table. Its gathering a list of all these photos, then looping through each one and resizing it 3 times. (large,medium,small version).
Right now on each loop I am echoing that images results, but I dont see the results untill EVERYTHING is done. So like 10 minutes later, I will get output. I added this set_time_limit(0); to make sure it doesnt time out.
**EDIT ** It looks like every so often the script actually updates to the browser, maybe every 30 seconds?
You can use flush() or ob_flush() to tell the script to send something back to the client after you do an echo().
BUT - you never really have complete control over it, the web server does, so the web server may not cooperate depending on how its configured. For example, if you have the server doing gzip rather than using PHP's gzip features, the web server may still buffer the output.

Categories