Valid XHTML 1.0 Transitional

Valid CSS!

Ysu Programming professional web development

Ysu Programming now operates as SmarterSoft.

design for Ysu Programming web development

A web devloper's diary

You could call it a blog, but why follow the other cattle out there? So it's my diary. :) You might guess it: I've a problem blending into the crowd. It's not always a good thing. But this is me.

13 Sep 2006 — set include dir via .htaccess for individual projects

I had to look it up today - again - and it's probably not as straightforward for some of us. So here's the simple how-to.

The problem is: sometimes we need to set the include_path for a project, as it was set on the original location, and to be able to locally work on the project without messing up the file structure this must be done. Obviously I don't want to set it for good, or for the whole server either.

Ok, let's see the following situation. The project is sitting in the d:\www\project\html directory, and the inludes are in the d:\www\project\inc directory. Now, if I want the program in the html directory to be able to use the 'inc' directory for the includes, I need to put a .htaccess file into the html directory. In this .htaccess file you need the following line:

php_value include_path "D:/www/project/inc/"

Oh, we need the "AllowOverride Options" or "AllowOverride All" set in apache - but that should not be an issue on a local test machine.

It was easy wasn't it?

31 July 2006 — strtotime is cheating!

Today I found out that for the month increment/decrement with strtotime 1 month=30days under some circumstances!

How come? look:
If you do this:

echo date('Y-m-d',strtotime('-1 months'));
on 31 july (2006-07-31), you 'll get "2006-07-01"

It's not going to substract a full month as you'd expect!

The most interesting part:

It has been reported as a bug on the, and deemed as bogus by some administrator, who obviously has a very strange calendar hanging on his wall....go figure.

1 june 2006 — The cURL problem

This is the first entry. I decided that every funny problem I run into I'll post about it here, someone may find it a bit of help.

The latest ugly problem I've been working on is with an online payment. I'm connecting to eway using cURL, and it works nicely as it should - most of the time, that is. But sometimes it seems to hang. The connection is built ok, the data is sent to eway - the payment is successful but the script on my side never leaves the curl_exec(), simply hangs. Timeouts don't apply either - for some unknown reason.

I've tried the hosting company for help, according to their test to eway's test-gateway the problem does not exists. I must agree, connecting to the test gateway the problem does not exists indeed. :) But they have wasted a lot of time trying to help me and now politely refused to help anymore. I can't blame them; they've probably spent a few month's account fee on it already.

I've tried to contact eway (3 times). This is via their priority oh-you're-so-important-to-us system, and email as well.
Now a week has passed. Nothing came, not even a blurp that they are alive.
Thank you, just the usual support (eg the lack of) you can expect nowadayss...

So now, after listening to others' ideas, I've built a system with fsockopen() instead of cURL, this way I've got heaps more control over what's happening. I've logged every byte going out and coming in, and found the known problem myself: Microsoft developers don't read standards.

The IIS (internet information server) drops the connection after the last byte sent without proper closing. It should send an 'eof' (end of file) to close it, but no, it just drops it. One solution to this is to send the header:
$headers .= "Connection: close\r\n";
but I'm just not sure it's always working, actually I suspect it's not.

Now in this case the timeout should apply - set with stream_set_timeout() - but it's just not working either. (Remember the timeout set at fsockopen() is only for the connection timeout, once the connection is built that timeout does not apply!)

So after all I decided on this:
I'm looking for the eway closing xml tag, and if found I'm dropping the connection myself too, just to be safe. :)
Here's the code, feel free to on it. As you can see I have to take care a couple of headers too, the first one is a HTTP 100 (continue), then the headers for the actual communication itself.

Oh well, I'll put here the fsockopen and header-in parts too.
The code is slightly edited from what is actually working online.

$fp = @fsockopen(
if ( !$fp ) {
  $this->myError = "$errstr ($errno)";
  $this->writeLog("fsockopen error: $errstr ($errno)");
} else {
  // part taken out; it builds the xml here, 
  // almost exactly as in the downloadable eway php object
  $headers = "";
  $headers .= "POST {$this->serverScript} HTTP/1.1\r\n";
  $headers .= "Host: {$this->serverAddress}\r\n";
  $headers .= "Content-type: application/x-www-form-urlencoded\r\n";
  $headers .= "Content-length: ".strlen($xmlRequest)."\r\n";
  $headers .= "Connection: close\r\n"; //to ensure the closing of the connection
  //send out the whole thing
  $sentReq = $headers."\r\n".$xmlRequest;
  fputs($fp, $sentReq );
  $this->writeLog("\nrequest was put in ok:\n$sentReq");
  $xmlResponse = $this->readDataStream($fp);

And now the data reader:
This is the function (method) retrieving the xml data after the connection is succesfully built with fsockopen() and the headers are sent.

function readDataStream(&$fp) {
  //variable declarations
  $line = null;
  $inHead = false;
  $xmlResponse = '';
  //set time-out
  stream_set_timeout($fp, $this->fsockopenTimeout);

  //get the response
  $lineNum = 0;
  while ( !feof($fp) ) {
    $status = stream_get_meta_data($fp);
    if ( !$fp || $status['timed_out']) {
      //if for some reason the connection is lost, stop right away
      $this->writeLog("\nConnection lost or timed out");
    if ( $lineNum>500 ) {
      //don't let it run forever, line limit here
      $this->writeLog("\nLine count over 500, stopping");
    $line = fgets($fp, 512);
    $line = trim($line);
    $this->writeLog("\nReceived line $lineNum:\n".$line);
    if ( strpos( $line ,"HTTP/1")!==false) {
      $inHead = true;
    } elseif ( trim($line)=='') { //empty line marks the end of head
      $inHead = false;
    if ( $inHead ) {
      $this->writeLog("\n(In head)");
    } else {
      $xmlResponse.= trim($line);
    if ( strpos($line,"</ewayResponse>")!==false) {
      //this way we forcefully end the reading not waiting for the eof which may never come
      $this->writeLog("\nLast line reached, stopping");
  $this->writeLog("\nReceived full: \n".$fullResponse);
  $this->writeLog("\nxml: $xmlResponse");
  return $xmlResponse;

What I'm still thinking of is what to do if there's no answer at all. But I figured in that case the php script will time-out, the transaction will not be registered on either side, so it's probably not a biggie.

Professional Web development at ysu programming logo

Ysu Programming now operates as SmarterSoft.
Integra PowerSuite CMS | Website Development | Online Marketing | Web Hosting | Custom Software (PHP / MySQL) | IT Consulting