Archive for the 'Scripting' Category

iPhone/iPad website body background image scales wrong when using jpg

I had a website i was working on http://www.indiansummerfestival.nl and i used a body background image in the top header image.
In every browser and on any Android device the body background image was scaled proportionally with the zoomlevel of the website on the device/screen.

But on iPhone and iPad the body background image was scaled to 100% width… On an iPhone the site was properly zoomed out to fit the width of the screen, but the body background image zoomed out more.. this messed up the design.

After spending some time figuring out what could cause this i finally found the solution.
When you save your jpeg as a Progressive jpeg it worked as expected.

No Comments »

PHP SoapClient exception Error fetching http headers

I had a problem with a soapclient and a strange error “Error fetching http headers”.
It seems the problem occurs when multiple soap call’s are done with a single soapclient instance.
I think the first soap connection is still “active” somehow, resulting in an error on the second soap call.

I started googling aroud and found this post which explains the issue in detail.
Creating a new soapclient for each call was the solution for me.
I hope this post can help someone with the same problem..

Below the original post for archive purposes:
http://php.blogaboutwhatever.com/2011/11/error-fetching-http-headers/

… really is as uninformative error message you can encounter during a call to some SOAP service. At least at the first glance. Digging deeper into the issue there’s some really interesting causes to that one.

Ok, first some more information. We do a SOAP call and sometimes end up with a SOAP fault ‘error fetching http headers’. Took some time to find the real reason for that.

Simple explanation why this can happen is if you have a default_socket_timeout setting of x seconds on your application and the remote SOAP server takes more than x seconds to answer.
So you system gets no response in time and starts complaining that it got no headers.

Reason one: slow remote SOAP service.

Some additional useful information: apache access log by default logs the time the request was started to be processed by apache, but it end up in log at the time the response is sent out. Requests that are not touched by apache do not end up in access log.

Well, we checked all available logs and could rule out a slow SOAP service for certain. No way it could run into a timeout. We could see logged error messages with ‘error fetching http headers’ on the client, but those requests
never ended up beeing processed by the SOAP server’s apache. After a bit of extended logging all looked like the client even never really sent the requests. So we started to search for a cause why the client thought
it had sent the request but in the same second already logged the empty response error.
At first we suspected some PHP SOAP client or openssl or whatever bug that tricked the client into believing it sent a request when it did not.

Alas, my colleague came up with an interesting link:

http://stackoverflow.com/questions/4824799/soapfault-exception-http-error-fetching-http-headers

which finally gave us the hint about where to look.

The client PHP code does the following: get instance of a class, in the class constructor initialize a SOAP client pointing to our SOAP server, make two SOAP calls. Then do something completely different, namely call a second remote system. After that call is done, the formerly initialized SOAP-Client is reused for another SOAP call and that is what went wrong sometimes.

We had a look at the headers:

Client sent this during request: Connection: keep-alive

SOAP server sent this in reponse: Keep-Alive: timeout=5, max=100

So here we have our reason: the server keeps the connection persistent for 5 seconds which is apache default. The client thinks the connection is persistent and it can call the remote server without sending a handshake first on all subsequent SOAP calls. That is ok if all calls can be done during 5 seconds. But if the call to the second remote system that takes place between SOAP call two and three takes too long, the third SOAP call ends up with ‘error fetching http headers’. Keep in mind, there were no unusual server configurations on any side!

Reason two: default setting of PHP and apache clashing with reusing a SOAP client in PHP.

Here we got, first fix: get a new PHP SOAP client for each call, the wsdl is cached by default so that does not slow the process down. At least it did not look like it did when I tested.

Second fix, but that one we only try to make our customer’s life a bit easier: raise Keep-Alive timeout on the SOAP server. That’s not so easy to be done, because we now might end up with more or longer running apache processes. So in time of high access we might run into trouble with a too high load on our SOAP server.

So note all you PHP developers out there: take care when reusing SOAP client instances, you might get hard to find errors. Playing it safe: never reuse the soap client, if you reuse you can try to try/catch the soap fault and retry with a new instance of SOAP client.

PHP SOAP documentation is not really helpful, maybe there’s some way to force SOAP Client into taking care with connections, but did not yet find it.

No Comments »

IE7 max tabindex problem #microsoft #fail

It took me an hour to debug some jquery in IE7. I was making a tab-navigation. When you click a tab it hides the content of the other tabs and shows the content of the clicked tab. Quite easy with jquery right? In all browsers except IE7 (I banned IE6 a long time ago..)

One of the tabs had a tabindex of 99999.
I added an alerts to display the value of tabindex attribute…
IE7 seems to have a max tabindex value of 16959!

Why? Only Bill Gates knows why….

1 Comment »

IIS7 Impersonate PHP Fast-CGI as local user

The problem i had that i had to talk to a dll through COM on a windows server in PHP.
I needed to run the site as another user than the standard IURS.
I tried setting the identity of the application pool, no success.

Finaly i found the solution;

The (default) website advanced settings page has the option to specify the Physical Path Credentials.
I set this to a regular system account, and checked within PHP with:

echo get_current_user();

Everything worked!

No Comments »

SVN and Mac OSX hidden .DS_Store ._ .AppleDouble files

If you work on a mac (as i do) your directories get poluted with .DS_Store, ._ and .AppleDoubel files. Apple (this is THE missing Finder feature!) has no option to turn this crap off.
Now when you use svn, you will also import all these useless files.

Thank god there is a option in svn to globally ignore specific files.
Just edit the file:

~/subversion/config

Find the line global-ignores, uncomment it and make it something like this:

global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store .AppleDouble ._*

Whoot!

No Comments »

sprint_r PHP function


1 Comment »

Alternate PHP exec() function bypassing cmd.exe

I had a problem running executables (like identify.exe and convert.exe from ImageMagick) from php under windows using the exec() funciton. The solution provided by others was kind off stupid… Give full permisions on cmd.exe to IURS… Like you wanna do that…..
I wrote a exec() replacement function using the bypass_shell option proc_open has. It works great for me. Do your favour with it.

";
			echo "Tempdir: ".TEMP_DIR;
			echo "
"; } $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w") ); $process = proc_open( $cmd, $descriptorspec, $pipes, TEMP_DIR, NULL, array('bypass_shell' => TRUE) ); if(!is_resource($process)) { return false; } if(!$pipes[1]) { if(DEBUG === true) { echo "No STDOUT
"; } return false; } $output = stream_get_contents($pipes[1]); fclose($pipes[1]); $err = stream_get_contents($pipes[2]); fclose($pipes[2]); $x = proc_get_status($process); $return_value = proc_close($process); if($return_value == 0) { if(DEBUG === true) { echo "Return value {$return_value}
"; print_r($x); echo "


"; } return explode("\n", str_replace("\r", '', $output)); } else { if(DEBUG === true) { echo "Return value {$return_value}
"; print_r($x); echo "Output: ".$output; echo "Error: ".$err; echo "


"; } return false; } } ?>

3 Comments »

ClamAV 0.94 not working anymore in MailScanner

I had this issue, clamav worked perfectly on command line, but within MailScanner it seemed to stop working. I could not find out why. I checked every configuration file, everything seemed normal.

Today i was upgrading ClamAV from 0.94 to 0.94.1, and suddenly i saw these lines in my maillog:


Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --unzip
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --jar
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --tar
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --tgz
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --deb
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --unrar
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --arj
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --lha
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --unzoo
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --max-ratio
Nov 12 09:01:39 mx02 MailScanner[26358]: WARNING: Ignoring deprecated option --unrar

Hmmmm.. weird. I started googling and found this bug:
https://wwws.clamav.net/bugzilla/show_bug.cgi?id=1213

They did this: Instead of hardfailing, clamd will print warnings.

Glad it is resolved now..

2 Comments »

Use your own HTML element attributes and make W3C validate correctly and make your browser display it like it should

Thanks to my College Joris (a.k.a. whizzrd) i wanted to make my website really Standards complient and not be satisfied with quirks mode but with standards mode.

Well, i did it, and this is how….

Make sure your page is served with Content-Type application/xml.
In PHP you can send this header:

header("Content-Type: application/xml");

Next on the top of your HTML you place this:

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="copy.xsl"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
[
<!ATTLIST td hoverimage CDATA #IMPLIED>
<!ATTLIST td normalimage CDATA #IMPLIED>
]>
<html xmlns="http://www.w3.org/1999/xhtml">

As you can see i defined two custom attributes for the td tag.
Now make sure you create a file named copy.xsl in your document root:
The file contains:

<stylesheet version="1.0"
xmlns="http://www.w3.org/1999/XSL/Transform">
<template match="/">
<copy-of select="."/>
</template>
</stylesheet>

IE should display your page like it should, but firefox has mysterious gaps when you use tables to make your layout (which you offcourse should not do to begin with 😉
Read this doc from mozilla dev to know all about why these gaps are there.

You can fix the gaps in FireFox by adding this style:

td img {
display: block;
}

Congratulations! You now have a w3c validating website in Standards mode.

You may have noticed your jQuery stuff is nog working anymore. In the Standards mode Mozilla does not generate implicit top-level JavaScript variable bindings for elements with the id or name attribute.
You can use your jquery stuff by not using the $ shortcut but calling jquery directly. See this example:

window.jQuery(document).ready(function() {
window.jQuery(".someelement a").hover(
function() {
//hover stuff },
function() {
//do other stuff
}
);
});

Well, thats it for now, hope you can enrich your life with this information and work on a unpoluted HTML world with me from today on.

Cheers..

No Comments »

Automatic frame redirect (cloaking) with apache and PHP

Sometimes a customer wants redirection using a frame. What you as an ISP don’t want to do is make webspace and a index.html file for each customer handling this. You want this automated somehow.
This is how i did it.

First set up redirection with apache.


    ServerName www.whatever.com
    ServerAdmin admin@whatever.com
    DocumentRoot /usr/local/www/apache22/data
    SetEnv FRAMEREDIRECTURL "http://www.to-where-ever.com/blah/blah"
    ServerAlias *.whatever.com whatever.com

As you can see we set a environment variable containing the URL you want to redirect to.
Next you will need some PHP to generate the frameset. Create this in the documentroot you specified in the virtual host.






<body>Please follow <a href="<?php echo $_SERVER['FRAMEREDIRECTURL'] ?>">link</a>.</body>


This is it. Use this info if you can.
Cheers

1 Comment »

Next »