PDA

View Full Version : Contacts Tutorial : backend timeout


JOakley
11-12-2004, 09:42 AM
Hi,

I have recently been introduced to the world of Laszlo and I have been eagerly trying to learn as much as possible.

As the title of the post implies I was working on the contacts tutorial and ran into a problem. I am using PHP to grab data from mySQL, turn it into XML and then it lets laszlo grab it, display it...works perfect. I got to the part with insert/update/delete and what not...nothing!

I continually get the error (debug mode):

NOTE:STRIPPED HTTP:// FROM ERROR MSG SO THE MESSAGE BOARD WOULD NOT TRUNCATE IT

"backend timeout for localhost/contactmgr.php?email=test%40test%2Ecom&phone=123%2D123%2D1234&lastName=lTest&firstName=fTest&pk=&action=insert: null http response body

And right now when I pasted that into this textarea I saw that I am not getting any of the data to populate the URL. I designed everything as per the tutorial with the exception of using php instead of jsp. How, help, please?

[LASZLO CODE]
<!-- data_binding.lzx -->
<!-- Tutorial Link: http://www.laszlosystems.com/lps-2.1.2/tutorials/data_app_8.html -->

<canvas bgcolor="#D4D0C8" debug="true">
<debug x="0" y="200" width="400" />
<dataset name="dset" src="http://localhost/getcontacts.php" request="true" type="http"/>
<!-- 1 -->
<dataset name="dsSendData" request="false" src="http://localhost/contactmgr.php" type="http"/>
<class name="contactview" extends="view" visible="false" x="20" height="120">
<!-- 2 -->
<text name="pk" visible="false" datapath="@email"/>
<text y="10">First Name:</text>
<edittext name="firstName" datapath="@firstName" x="80" y="10"/>
<text y="35">Last Name:</text>
<edittext name="lastname" datapath="@lastName" x="80" y="35"/>
<text y="60">Phone:</text>
<edittext name="phone" datapath="@phone" x="80" y="60"/>
<text y="85">Email:</text>
<edittext name="email" datapath="@email" x="80" y="85"/>
<method name="sendData" args="action">
var d=canvas.datasets.dsSendData; // 3
var p=new LzParam(); // 3a
p.addValue( "action", action, true);
p.addValue( "pk", pk.getText(), true);
p.addValue( "firstName", firstName.getText(), true);
p.addValue( "lastName", lastName.getText(), true);
p.addValue( "phone", phone.getText(), true);
p.addValue( "email", email.getText(), true); // 3b
d.setQueryString( p ); // 3c
d.doRequest(); // 3d
</method>
<!-- 4 -->
</class>
<simplelayout axis="y"/>
<view>
<simplelayout axis="y"/>
<text onclick="parent.newContact.setVisible(!parent.newContact.vi sible);">New Entry...</text>
<contactview name="newContact" datapath="new:/contact">
<button width="80" x="200" y="10">Add
<method event="onclick">
parent.sendData("insert"); // 5
parent.datapath.updateData();
var dp=canvas.datasets.dset.getPointer();
dp.selectChild();
dp.addNodeFromPointer( parent.datapath );
parent.setVisible(false);
parent.setDatapath("new:/contact");
</method>
</button>
</contactview>
</view>
<view datapath="dset:/phonebook/contact">
<simplelayout axis="y"/>
<view name="list" onclick="parent.updateContact.setVisible(!parent.updateCont act.visible);">
<simplelayout axis="x"/>
<text datapath="@firstName"/>
<text datapath="@lastName"/>
<text datapath="@phone"/>
<text datapath="@email"/>
</view>
<contactview name="updateContact">
<button width="80" x="200" y="10">Update
<method event="onclick">
parent.sendData("update"); // 6
parent.parent.datapath.updateData();
</method>
</button>
<button width="80" x="200" y="40">Delete
<method event="onclick">
parent.sendData("delete"); // 7
parent.parent.datapath.deleteNode();
</method>
</button>
</contactview>
</view>
</canvas>

[PHP CODE]
<?php
$host = 'localhost';
$user = 'user';
$password = 'password';
$database = 'database';

$conn = mySQL_CONNECT("$host", "$user", "$password") or die(mySQL_ERROR());
mySQL_SELECT_DB($database, $conn) or die(mySQL_ERROR());

$action = $_GET['action'];

$email = $_GET['email'];
$firstName = $_GET['firstName'];
$lastName = $_GET['lastName'];
$phone = $_GET['phone'];

if ($action == 'insert') {
mySQL_QUERY = ("INSERT into contact (email,
first_name,
last_name,
phone) " . "
VALUES ('$email',
'$firstName',
'$lastName',
'$phone')");
} else if ($action == 'update') {
mySQL_QUERY = ("UPDATE contact SET email = '$email',
first_name = '$firstName',
last_name = '$lastName',
phone = '$phone'
WHERE email = '$pk'");
} else if ($action == 'delete') {
mySQL_QUERY = ("DELETE * FROM contact WHERE email = '$pk'");
}
?>

d~l
11-13-2004, 07:59 AM
can you post your other php file for testing?
there are two php references in your lzx app ..
getcontacts.php and contactmgr.php

JOakley
11-15-2004, 06:25 AM
Sorry d~l...I registered my account to work and didn't see the reply notification. I forgot all about this file.

Here ya go..

EDIT (CHANGED TO CORRECT FILE)

<?php
function do_xml () {
$host = 'localhost';
$user = 'user';
$password = 'password';
$database = 'database';
// Connect
$conn = MySQL_Connect("$host", "$user", "$password") or die(MySQL_error());
MySQL_Select_DB($database, $conn) or die(mysql_error());

// Query the db
$sql = MySQL_Query ("SELECT * from contact ORDER BY email ASC");

// Begin XML display
echo '<phonebook>';

// Loop through db fields and display data in XML format
while ($line = mysql_fetch_array($sql)) {
echo '<contact firstName="'.$line['first_name'].'" lastName="'.$line['last_name'].'" phone="'.$line['phone'].'" email="'.$line['email'].'" />';
}
// End XML
echo '</phonebook>';
}

// Set header type to XML
header('Content-type: text/xml');
// Perform Function
do_xml();
?>

d~l
11-15-2004, 06:35 AM
isn't that php file the same as the one you posted earlier?

just zip all three files and attach them here .. to be tested.

JOakley
11-15-2004, 07:21 AM
Crap! Sorry. UPS called me at 6 this morning and now I'm sleepy.

Here are the three files attached.

d~l
11-29-2004, 07:18 AM
Returning to this problem .. after a "timeout" ..
...

First, in contactmgr.php there was an error in mysql query syntax .. should read like this ..


// Insert
if ($action == 'insert') {
$query = ("INSERT into $tablename (email, firstName, lastName, phone) " . " VALUES ('$email', '$firstName', '$lastName', '$phone')");
$result = mysql_query($query);


use same two line syntax
$query =
$result =

for update and delete .. just change the query line .. and follow with $result line

__________________________________________________

but even getting the php to work on mysql .. I still get the error message "backend timeout" .. as you reported ..

although the records are being placed correctly into mysql database .. as verified by phpmyadmin ..

__________________________________________________

then tried changing LPS configuration in c:\tomcat5\webapps\lps-2.2\WEB-INF\lps\config\lps.properties

backend http properties
to be ..

http.backendTimeout=30000
http.backendConnectionTimeout=30000

restarted Tomcat server ..

but still see the "backend timeout" message .. and even before the 30 seconds timeout (as in lps.properties settings above) has expired.

__________________________________________________

added note ..

Then found these two additional configuration variables here deployers guide (http://www.laszlosystems.com/lps/docs/deployers-guide.html) .. and added them to lps.properties ..(don't know why they are omitted).

http.maxBackendRetries=3
http.retrySleepMillis=200

but still seeing "backend timeout" message!

__________________________________________________

So .. what is generating this "backend timeout" message .. since there is no mysql timeout, no returned error message from php, and the mysql database management is working?

__________________________________________________


Tip taken from .. this thread on setQueryString (http://www.laszlosystems.com/developers/community/forums/showthread.php?threadid=346&highlight=setQueryString)

If in data_binding.lzx this line is placed immediately after d.setQueryString ( p ); //3c

Debug.write("Query string: " + d.getQueryString());

The URL variables sent in query string to the php files can then be seen in debug window ..

__________________________________________________

Further note .. in the updating, deleting and inserting data tutorial (http://www.laszlosystems.com/lps-2.1.2/tutorials/data_app_8.html)

if you experiment with the alternative syntax shown on that page .. location 3c ..


d.setQueryString( { action: "action",
pk: pk.getText(),
firstName: firstName.getText(),
lastName: lastName.getText(),
phone: phone.getText(),
email: email.getText() } );

the first variable should be corrected to action: action .. not action: "action" as printed.

If the quotations are introduced (as in the tutorial) the action variable is passed to the querystring as

&action=action .. and not

&action=insert
&action=update
&action=delete


But this tutorial "typo" error is not relevant to the "backend timeout" problem ... just added here for information.
__________________________________________________