View Full Version : Stream Error 2032 = Php connection, but only sometimes (?)
nightkarnation
07-07-2011, 04:00 AM
Hello Guys,
I have a swf file which is very demanding,
My code retrieves data from a php file every 100 Milliseconds (using a timer) (and that php queries to a mysql database)
Connection is done perfectly and the data is retrieved every single time.
But recently, I moved from a shared hosting to a dedicated server (due to the demanding queries) and now I am having a problem...
Every 20 min approximately (sometimes more, sometimes less, I get the following error:
Error #2032: Stream Error. URL
Other check using: varLoader.addEventListener(HTTPStatusEvent.HTTP_ST ATUS, onHTTPStatus)
HTTP_STATUS gives me a result of: 0, when I get the stream error.
(instead of 200 when the complete handler works, which is almost all the time)
The problem is that when I get the error, my swf just STOPS, is there any way I can bypass this error and/or any other suggestions on what I could be doing wrong?? Maybe my dedicated server has an overflow protection?? is this possible?
Or something else I am not thinking?
Here is an example of the successful connection I make from flash to php:
var variables:URLVariables = new URLVariables();
var d = new Date();
var kill = d.getTime();
var varSend:URLRequest = new URLRequest("http://www.mysite.com/php/Main.php?kill="+kill);
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
varLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError)
varLoader.addEventListener(HTTPStatusEvent.HTTP_ST ATUS, onHTTPStatus)
variables.action = "retrieveAuctionsDynamicInfo";
varLoader.load(varSend);
function onIOError(evt:IOErrorEvent)
{
trace("IOError: "+evt.text)
}
function onHTTPStatus(evt:HTTPStatusEvent)
{
("HTTPStatus: "+evt.status)
}
// When the data comes back from PHP we display it here
function completeHandler(event:Event)
{
//DATA RETRIEVED FROM PHP...BLAH BLAH BLAH
}
Thanks A LOT in advance!!
Cheers,
audiopro
07-09-2011, 04:22 PM
My initial thought is, why do you need to retrieve data every 100 milliseconds?
Getting the same data every second would give the user the same experience.
I have seen this type of overloading with badly coded 'chat rooms' which update at similar rates, updating a chat room every 3 or 4 seconds is perfectly acceptable.
It might help if you can give us some idea of what type of data you are getting from the server.
nightkarnation
07-11-2011, 05:06 PM
Hello Audiopro,
First of all, thanks a lot for your reply!
I have an auction site and it requieres me to update every second in order to check for new bids.
If I check every 1000 milliseconds instead of 100, The clock showing the countdown of the auction (retrieving the hour from the server) might skip 1 second due to the milliseconds on flash not being 100% accurate, correct?
I am getting the servers time comparing to the last bidder time, and item auction string variables.
Hope this helps a little bit in order to understand my current problem.
Please let me know if you need more information,
Cheers!!
audiopro
07-11-2011, 06:21 PM
I think you are over estimating the accuracy of timing over the internet. If you are only retrieving the hour from the server then the server time and visitor's time could be a long way out any way. Even if the minutes are the same, the 2 timers could still be a minute out so a few seconds is not worth bothering about.
That is with no glitches on the server itself, which could cause even more problems.
nightkarnation
07-11-2011, 07:26 PM
Hello Audiopro,
The last bidder time is also saved using the server time, so that is not a problem. The time is accurate but flash isnt fast enough to save/load the queries, plus the error that sometimes pops up.
If I perform the same tests directly on php, the queries are done perfectly and at perfect speed.
Flash is slowing me down,
Do you think theres a way to optimize this code:
var variables:URLVariables = new URLVariables();
var d = new Date();
var kill = d.getTime();
var varSend:URLRequest = new URLRequest("http://www.mysite.com/php/Main.php?kill="+kill);
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
varLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError)
varLoader.addEventListener(HTTPStatusEvent.HTTP_ST ATUS, onHTTPStatus)
variables.action = "retrieveAuctionsDynamicInfo";
varLoader.load(varSend);
function onIOError(evt:IOErrorEvent)
{
trace("IOError: "+evt.text)
}
function onHTTPStatus(evt:HTTPStatusEvent)
{
("HTTPStatus: "+evt.status)
}
// When the data comes back from PHP we display it here
function completeHandler(event:Event)
{
//DATA RETRIEVED FROM PHP...BLAH BLAH BLAH
}
Thanks a lot in advance!!
LOLFlash
07-11-2011, 10:29 PM
import flash.utils.getTimer;
function completeHandler(event:Event)
{
varSend.url="http://www.mysite.com/php/Main.php?kill="+getTimer();
varLoader.load(varSend);
trace(getTimer())
}
what is your trace?
nightkarnation
07-11-2011, 10:46 PM
Hi LOLFlash
Single test: getTimer trace: 14290
Test Every second/connection: 2877, 4377, 4810, 5476, goes up, goes up, 24042, etc...
???
LOLFlash
07-12-2011, 02:50 AM
I don't think you will be able retriever data every 100 Milliseconds. Your packets are staking because server respond time approximately 1 sec for http request in your case. You should redesign connector.
collect data in array and send it to server on every respond the same time receive data pack what good for next second or two util you have next respond.
If you have data transfer faster then expected override it. It means each data has to have unique id for corrections
that a brief description of relay connector what I would do
audiopro
07-12-2011, 04:54 AM
I would still slow the whole process down and not worry so much about precise accuracy.
The big, well known auction site only updates the client side 'remaining time' value after a manual refresh so even they don't worry about accuracy too much.
nightkarnation
07-12-2011, 09:10 PM
audiopro, I agree with you, I have been doing some tests and what you suggest is the best.
Here is a side but related problem that I am having:
I am having a problem sending 7 querys at the same time through Flash...I tried directly from php and its working Perfect! the problem through Flash is that the 7 querys are being sent from 1 to 3 seconds...and directly from php it takes less than 1 second (which is exactly what I need)
I need that same or at least 1 second in speed from flash to php/mysql.
Here is a simple example on how it works perfectly directly from php:
Code:
for ($i=0; $i<7; $i++)
{
$result = mysql_query("UPDATE `MAIN` SET Current_Price = Current_Price + '$increase_price[$i]', Bids = Bids + 1, Last_Bidder = '$last_bidder[$i]', Last_Bidder_Time = '$last_bidder_time' WHERE Id = '$id[$i]'");
}Here is how its done with flash and php:
As3 Code:
Code:
function submitBid1(itemSlot:Number)
{
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("http://www.mysite.com/php/main.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
variables.action = "sendBid";
variables.Id = itemId;
variables.Bidder = username;
variables.UserId = userId;
variables.IncreasePrice = itemIncreasePrice;
// Send the data to the php file
varLoader.load(varSend);
// When the data comes back from PHP we display it here
function completeHandler(event:Event)
{
//ETC, ETC...CONFIRMATION RECEIVED FROM PHP
}
}PHP CODE FOR FLASH:
Code:
if ($action == "sendBid")
{
//grab values from flash
$id=mysql_real_escape_string($_POST['Id']);
$last_bidder=mysql_real_escape_string($_POST['Bidder']);
$user_id=mysql_real_escape_string($_POST['UserId']);
$increase_price=mysql_real_escape_string($_POST['IncreasePrice']);
$last_bidder_time = date('D M j H:i:s \G\M\TO Y');
$result = mysql_query("UPDATE `MAIN` SET Current_Price = Current_Price + '$increase_price', Bids = Bids + 1, Last_Bidder = '$last_bidder', Last_Bidder_Time = '$last_bidder_time' WHERE Id = '$id'");Any ideas and/or suggestions as to why Flash is taking more time than php to perform the querys?? Is there a way to optimize flash/php/mysql ???
Thanks a lot in advance!!
Cheers!
LOLFlash
07-13-2011, 03:39 AM
This why I'm a Flash programmer. People of VB considering .net as an advance topic where it is start point for Flash application.
nightkarnation: you have a little misunderstanding levels of network communication. HTTP request wasn't design for strait connection but for reliable asynchronous data exchange in Internet. Speed of response time depends not only from latency but network and server configuration. It designed to serve large amount of clients in a chaos of Internet.
If you need speed you probably have to go for Socket but ping your server first to confirm your expectations.
audiopro
07-13-2011, 08:00 AM
I am not familiar with using URL request as I usually use Loadvars but that aside, one thing does intrigue me, why are you issuing 7 queries.
Fom my understanding you would require 2 independent PHP scripts.
NEW BID
Flash sends details of the bid to PHP which updates the MySQL database and returns a confirmation to flash that the bid was accepted.
CHECK BID STATUS
Flash contacts the MySQL database to check for new bids and returns any new bids placed since the last check.
In reality you would have more scripts than this to deal with admin etc. but I am only dealing with the bidding process.
The second script would be the one hammering the server if many users were on the site at once but would only be like having a HTML based chat script.
LOLFlash
07-13-2011, 04:50 PM
If Flash your main application in a system it is a good practice move to AMF data exchange what reduce amount ob bytes 3 times compare to URLLoader or LoadVars
http://en.wikipedia.org/wiki/Action_Message_Format
Adobe promote ZEND-amf classes integrated into Flex compiler , AMFPHP the oldest and easy to use solution.
when I have time I want to try sabreamf
nightkarnation
07-14-2011, 02:48 AM
Hey again guys!
I am moving to AMFPHP and it seems to be working A LOT better than URLLoader or LoadVars !!
Thanks a lot for the kind help!!
audiopro
07-14-2011, 07:03 AM
No idea what AMFPHP is butif you have found a solution - great.
I don't use much PHP, I mostly use Perl.
You didn't explain why you need 7 queries.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.