Thursday, April 3, 2008

Error: No space left on device - PHP, IIS, Win2K3

Today I went to upload on one of my client's sites and realized that the uploads were not working.

After looking at the directories and permissions to ensure that they were not deleted, I went back to see that the directories that were suppposed to be created with each upload where not being created.

I went to turn error reporting on the php script:

error_reporting(7);

this error appeared on the IIS 6, Windows 2k3 Box.

Warning: mkdir() [function.mkdir]: No space left on device in E:\Domains\www.domainname.com\html\upload_new.php on line 75

I checked and there was enough space left on the device. I moved the upload to different drive and that seemed to work. But no matter what I did on the upload directory permissions wise, I was still receiving the same error.

After going crazy for a while, I found a post online that could be very helpful in debugging if my post does not solve your problem.

It ended up being that the IUSER_XXXXX ran out of space for their disk quota and was not being allowed to write to the disk. There are a few ways that you can fix this, but I don't need quota's turned on for this machine and I don't care if they go over the quota, so I chose to just turn the enforcement off. You could easily delete files to go back under quota or raise the users quota.

You can change your quota rules by going to your volume or drive (e: in my case) and right clicking and selecting properties. There you can see a quota tab. There are a few options here (which I will not get into), but to fix the problem you can easily just click a checkbox which will stop the system from enforcing quota rules (it will stop disabling people if they go over the quota). Likewise, you can change your quota limitations on this screen.

If you find this useful, please digg me, link me, or click on a sponser for which you find legitimate interest.

Labels: , , , , , , , , ,

Sunday, March 30, 2008

Subtotal Not Adding Up Correctly in PHP (with Items over 1000)

I am on a few list serves and occasionally I am able to get a few of the questions answered. I will post some of them on my blog occassionally in case you run into the same issues. In this case, one of my fellow programmers ran into an issue where his subtotals where not adding up properly. I had run into the same issue myself. Just read below. It is simply a matter or recognizing that your variable might be formatted to display with a comma, such as 1,432.12


----- Original Message -----
From: Matt
To: List
Cc: Mauricio
Sent: Sunday, March 30, 2008 11:48 PM
Subject: Re: it it a php bug? or am i just slow?

That was it!!

apparently the ',' was settype()ing it on the fly as a string, so when it came to the += it was evaluating wrong..

Many thanks Mauricio!

Mauricio Zuniga - Systems Engineer wrote:
also,
even though you are giving us the values,
could it be possible that you have your number formatted with a comma?
such as 1,321.43.
I once ran into an issue where my subtotals were not correct because of this...
----- Original Message -----
From:
To:
Cc:
Sent: Sunday, March 30, 2008 10:29 PM
Subject: Re: it it a php bug? or am i just slow?

I set up the following loop:
$item_price = 0;
$items = array(50, 100, 1357);
foreach ($items as $v) {
$item_price += $v;
echo "
$item_price";
}
and it gave the following output:
50
150
1507
which is what was expected.

Could you post the actual loop code you are using? Perhaps there is something there we can help with?

Daniel

Mattwrote:
Not sure if this is a bug in PHP, or if I'm just especially slow...

I've got a script that's calculating the total order for items in a cart. To do this it's doing a simple += on the variable $subtotal as it prints each row on the cart page, then it prints $subtotal in the appropriate spot at the end. So on its way through the loop that prints each row, right at the end of the loop it does:

$subtotal += $item_price;

Simple, straight forward, not a problem.

It works perfectly fine. IF the value of $item_price <= 999.99 (?!??!!!?!?!?!?)

Anything >= 1000.00 and it adds 1 to subtotal, not the $itemprice. (?!?!?!?)

I've echoed $item_price and $subtotal while the loop is printing, I get results as below:

// first iteration
echo $item_price; // 50.00
echo $subtotal; // 50.00

// second iteration
echo $item_price; // 100.00
echo $subtotal; // 150.00

// so far, so good, right?

// third iteration
echo $item_price; // 1357.00
echo $subtotal; // 151.00

/// what??

// fourth iteration
echo $item_price; // 100.00
echo $subtotal; // 251.00


Any ideas? The only option I've considered so far is chucking every computer in the house out the damn window and becoming a carpenter, but I'm still on the fence about that.


-M.E.


--
_________________________________________



--
_________________________________________




Labels: , , , , , , , , , , , ,

Thursday, March 6, 2008

Mysterious Page Loading Twice Issue

Today I dealt with a very mysterious issue.
Every time a page would load, it seemed to reload.

I cannot actually explain what was happening to be honest... but i was able to track down the culprit to a problematic table tag:
<table border="0" cellpadding="0" cellspacing="0" width="100" background="#DEEFEF" id="sidebartable">

the problem ended up being in the background tag...
once I changed this background tag to bgcolor it worked fine!
<table border="0" cellpadding="0" cellspacing="0" bgcolor="">


This was some extremely bizarre behavior and what I did to debug it: I disabled pieces of code until I could isolate where the issue was stemming from. Even then, it took me a while to see that the tag and fix it. I ended up spending a good 2 hours just isolating the piece of code that was causing the issue. I would never have guessed; I honestly still can't explain it. If you know what is going on, I would love it if you told me.

Labels: , , , , , , , , ,

Flex Upload IO File Error

So we kept getting the infamous file io error when we were doing some very large uploads with our flex upload. We spent a lot of time debugging this and we kept thinking that it had to do with the HTTP Keep Alive on PHP level.

The symptoms are as follows:
User uploads file and it seems to go fine or get through most of the way.
Upon completion of upload (or not), the flex module hangs at 100% uploaded or returns a File IO Error (or similar).
The upload module will work through PHP in most cases, usually when the large files are uploaded, this is when you have issues.

This is what I did to debug the issue.
I went into the PHP tmp folder to actually watch the files as they uploaded. From here I was able to start discerning a pattern of what was happening. It seemed that the file was getting stuck at 5:00 minutes exactly. I was able to replicate the issue and I realized that the process which was handling the upload, must be getting stuck or timing out.

Since it is PHP that is handling the file upload, I went on see what was in phpinfo(). I noticed that the HTTP_Keep alive was exactly 300 seconds = 5 minutes.

This lead me (eventually to the right location), but it was not the http keep alive. I went through regedit in windows and actually searched all the registry kees for the term alive and also for a value of 300.

Nothing seemed to add up.
I eventually remembered that there were several settings in the IIS Metabase that are usually hidden (or rather deep). I went through and did a search for 300 (seconds). I found that the cgi timeout setting was set to exactly this.

I changed this setting to a much higher value, and what do you know... it solved the problem. The CGI timeout value will limit how long your upload will last, so be sure that it is adequate for the size of files that you will be expecting.

Labels: , , , , , , , , , , , , , , , , , ,

Wednesday, January 30, 2008

Warning: I am able to write to the configuration file: Windows, Helm, Zen Cart/OS Commerce, and File Properties

Ok, so I am not too proud to admit that I am moving from a linux box to a Windows environment for many of my projects. Suffice it to say that it was not originally my idea and it ends up being a complex situation of cost and performance. In my defense, the windows hosting that I am using has newer versions of php and mysql and is a clustered, load balanced system as opposed to the single linux box. I was kicked off the linux box for having too many domains and taking up too much processing power, but that is another post I will make later.

In any case, I was porting over my Zen Cart installations to the windows environment. And everything went fairly smooth until I ran into the
"Warning: I am able to write to the configuration file:"

As I did research, i found this was supposed to be an easy fix of setting the file permissions to 644 or 444. Well low and behold, this was actually not that easy in my situation: I tried to set these permissions through dreamweaver, filezilla ftp, and then even through the IE Ftp interface... and still no luck. I went in through helm and tried to use the file manager, but it does not allow for setting file permissions.

I ended up putting in a ticket to my hosting company to see if they can help. Apparently all you need to do is look at the file from the OS, right click on it and then set to read only- and voila you should be fine. Well, I realized I did not want to have to rely on my hosting company for changes to these files every single time I want to update or change configuration (which would not be often, but I have a few other installations of zen cart I wanted to do on this server).

As I was waiting for response, I came up with the idea to try to set the file permissions through php or asp. I set out on a quest and found some code which I altered ever so slightly to get to work on my system... Here it is. Just make a setfilepermissions.asp page on your server. This page will just do one thing and this is to set the filepermissions to readonly. You will have to alter the code to make it dynamic or set the file back from read-only.

If you do add or change it, please post it here. Thanks!


......................................


response.write "i am in here"


Dim strSaveFilename
'As String

Dim scrFSO
'As Object 'Scripting.FileSystemObject
Dim scrFile
'As Object 'Scripting.File

'i used absolute path which worked for me
strSaveFilename = "c:\domains\your domain here\wwwroot\includes\configure.php"


' Set up Scripting variables
Set scrFSO = CreateObject("Scripting.FileSystemObject")
Set scrFile = scrFSO.GetFile(strSaveFilename)

' Set file to be read-only
scrFile.Attributes = 1 'ReadOnly

' De-reference variables
Set scrFSO = Nothing
Set scrFile = Nothing

response.write "
done setting permissions!"

Labels: , , , , , , , , , , ,

Saturday, January 12, 2008

Email Elements on Web Page - AJAX Solution

So yesterday I had to quickly come up with a solution to send out an email of a web page that was already rendered. I could go back through all the php server side code and try to hold all of the information in a cache variable that would then also email out the rendered html. This provided me with many complications and issues as I would then have scope to worry about in certain situations and some of the functions had been expressly written to spit out html as they run.

If you have read this far, then you understand the plight..
I came up with the following solution: I decided to try and create an AJAX solution. This is what I did:

Create a div container in your html. This Div Container should encompass everything yould like to appear in your email.


<DIV id="Email">

INSERT YOUR HTML IN HERE

<DIV>


now before this Div element, you will need to declare a form. Here you can declare where your destination ajax call ill be (ajaxsendemail.php), what to call on submit. We are disabling submit via html via return false. You can also see from this code that we have a button which will trigger the call to send the email.



<form id="emailForm" name="emailForm" method="post" action="ajaxsendemail.php" onsubmit="sendEmail(); return false;">

<input name="Send Email" type="button" value="Send Email" id="Send Email" onclick="sendEmail();"/>

<input type="text" name="to" id="to" value="recipient@email.com"/>

<input type="text" name="subject" id="subject" value="Email" />

<textarea>


<DIV id=/"Email">

INSERT YOUR HTML IN HERE

</DIV>


</form>



What you will need to know now is that we will be taking the html contents in the div container we created, then via ajax, we will send this html code through a post method to a php script which will then send the email to your desired destination. Please note that you will need the zxml javascript library:
Which the latest version that I have is here: zxml.js. Please be sure to check (and let me know) if there is an updated version.

So first, we will need to include some javascript on our page, preferably before the div container.

<script type="text/javascript" src="zxml.js"></script>

<script type="text/javascript" >



function sendEmail(){



var oForm = document.emailForm;

var sBody = getRequestBody(oForm);



var oXmlHttp = zXmlHttp.createRequest();

//alert(sBody);

oXmlHttp.open("post", oForm.action, true);

oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

oXmlHttp.onreadystatechange = function () {

if (oXmlHttp.readyState == 4) {

if (oXmlHttp.status == 200) {

//saveResult(oXmlHttp.responseText);

alert(oXmlHttp.responseText);

} else {

saveResult("An error occurred: " + oXmlHttp.statusText);

alert('error code');



}

}

};

oXmlHttp.send(sBody);

}



function getRequestBody(oForm) {

var aParams = new Array();



for (var i=0 ; i < oForm.elements.length; i++) {

var sParam = encodeURIComponent(oForm.elements[i].name);

sParam += "=";

sParam += encodeURIComponent(oForm.elements[i].value);

aParams.push(sParam);

}

//email body

var sParam = encodeURIComponent('emailBody');

sParam += "=";

sParam += encodeURIComponent(document.getElementById("Email").innerHTML);

aParams.push(sParam);



return aParams.join("&");

}

</script>



Simply speaking, getRequestBody() takes all the form elements that you have made and then creates a Post Body request. In here I have added a bit of code which simply takes the div element (called Email) and creates another Post Variable from this element. You could do this for multiple elements in your document. The send email, instantiates the ajax transport method and calls the getRequestBody to create the post body, which is sent in the command oXmlHttp.send(sBody); . I simply created an alert to let you know what happened with the Ajax call (was the email successful?).

Now we have to take a look at the php code which handles the actual email.
ajaxsendemail.php

<?php

$to = $_POST['to'];

$subject = $_POST['subject'];

$body = '<style type="text/css">

<!--

body,td,th {

font-family: Arial, Helvetica, sans-serif;

}

-->

</style>'.stripslashes($_POST['emailBody']);

$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'From: Orders@NitroPrint.com <Orders@NitroPrint.com>' . "\r\n";


if (mail($to, $subject, $body, $headers)) {

echo("Message successfully sent!");

} else {

echo("Message delivery failed...");

}

?>




that pretty much takes care of it... I hope you will find this useful. If you have the time, please click through one of our fine sponsors.
In addition, if you have any difficulties or suggestions, please let me know.

Labels: , , , , , ,

server crash!!

So I run a few different websites with a few different companies. I have been buying up web domains or what I'd like to call virtual estate. But that is neither here nor there really... as I would like to be spending my time doing research on great domain names to buy up. Unfortunately at about 4:00 am I was going up to bed after a long night of watching bad movies and configuring domains. I noticed something was wrong with the server. I tried to login remotely and no dice... This is my personal server, where I do most of my development and host a few smaller sites. Luckily the financial impact is somewhat minimal at this point, but the frustration has taken it out of me.

As it turned out the server was toast, something happened to the boot sector and the OS, which had been suffering from another semi crash a few weeks ago, had decided to give way. It took me quite a long time to fix it as I was actually gullible enough to believe that I would be to able to repair the os properly. Well, I ended up re-installing SBS2k3... and now as I think back, I would recommend that if at all possible, go with Windows Server Standard Edition 2k3. Too much overhead with what I have deemed useless gadgets and services that are great for a small to midsize company, but not ideal if all you want to do is host a website and SQL Server. Why did I sign up for SBS then? It was a deal with the server.

So the quick lesson... code in php, use XAMP ;).

Just kidding - that's my preference, but I have a few clients that work with SQL Server/MSDE (and a few legacy systems I developed in classic ASP) - so that's not really a choice.

Anyhow, with all the frustration and and work to completely reinstall I came up with a few tips that might help - especially if you are trying to salvage your data:

- try to install a new os on a different partition. Do not create a new partition at this point. It is possible, but not likely you will succeed in creating a new partition AND save all your data. Didn't you make multiple partitions when you installed the system? Oh.. well, this is a good reason why you might want to do that.

- if you do not have a new partition to work on, or you really want to try to repair your system, try to the system repair with windows. Take out your cd-rom, insert it and boot with it. Do not press f2 on load up for the automated system restore... you will have to let the blue screen load until it prompts you if you want to (R)epair. You wan to try to repair your system (keep your eye on the screen).

This will overwrite all your major system files and try to restore your system from initial installation. If this is successful, you might get your system to boot, but you will then have to reapply pretty much all patches, service packs, and perhaps reinstall several applications.

I am no expert , more of a crazy mad scientist, so don't blame me if you mess your system up even further.

- upon finally loading the system, I was able to reinstall SQL server. If you know this trick, move on. But you can always go to databases, right click on databases- and choose the actino "attach database" file directly from enterprise manager. The system will prompt you for the location of hte data files. You can take the databases from your crashed os, and just attach them again. Although if you have sustained system damage, you might want to consider moving the files to a clean location.

- if you have mysql as well... also on the server... you can take the datafiles folder and copy and paste all those datafiles into your new mysql datafiles folder. Mysql Admin should recognize them the next time it checks the folder.

This saved me quite a bit of time as to how I was going to get the latest data from the databases since my db backups were not as current as they could have been.

- I was also able to reinstall FTPZilla Server to the same exact folder it was installed in previously, and this saved me from having to reconfigure.

- also had quite a bit of trouble getting php to work. I had it previously downloaded and tried to use the files I had previously. I took the latest version from Php.net and it worked fine. Normally, I like to archive versions I have worked with in the past for easy installation and recovery such as this case. Pros: For the installation of MySql, this was really handy. I tried searching online, and I am not sure what MySQL is doing, but they are making it seem harder and harder to find the open source free versions. After looking on my archive drive, I got it installed in 2 minutes. On the other hand, Sometimes trying to use older versions doesn't work in your favor to save time, as in the case of PHP.

- Now I'm running all sorts of checks, defrags, and drive analyses... but the server is back up and running. Hoping for a better Day tomorrow.

Labels: , , , , , , , , ,