473,809 Members | 2,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

(For gurus) Embed functions in webpages like in PHP?

Hi,

I'm a PHP-programmer who evaluates Python for a new project.
I really like a lot of concepts of Python, especially the shell, but there
is one great feature of PHP which I don't know how to replace in Python:

For database-intensive webpages, I like to cache the HTML-output on the fly
in the filesystem and put out the file later whenever the same URL is
requested again, for example:

/cache/some_url:
<html>
important database result that took 20 minutes to generate
</html>

and:
/www/master_script.p hp:
<?
if (is_file("/cache/$URL")) include("/cache/$URL");
else include("/scripts/soo_long_and_co mplicated.php") ;
?>

So far so good, shouldn't be too much of problem to do something similar in
Python.

However, it's sometimes necessary to still access the database, for example
to rotate banners, show user-specified style-sheets, change output
depending on the used browser, etc.
In PHP it's trivial to do this, instead of caching the output of a function,
I just cache "<? function(); ?>", so the example looks like this:

<html>
<? echo random_banner() ; ?>
important database result that took 20 minutes to generate
</html>

I've used this technique for about a year now and it works great for
semi-static pages (which are manually changed) or some not too fast
changing dynamic pages, in some cases I reduced the database-load to 20%.
The beauty of it is that I can use the same "random_banner_ ()" function for
the cache and on the fly.

As far as I've seen, there is no way to embed Python-code in a webpage with
"<? ?>" or anything equivalent and I don't see any other way to solve this
problem.

But maybe somebody else does, I'd apreceate all ideas,

Thanks a lot

--
"I don't suffer from insanity, I enjoy every minute of it"
- Calvin

Jul 18 '05
11 1767
Thomas Guettler wrote:
Am Fri, 16 Apr 2004 12:38:16 +0200 schrieb Robert Ferber:
Hi,

I'm a PHP-programmer who evaluates Python for a new project.
I really like a lot of concepts of Python, especially the shell, but
there is one great feature of PHP which I don't know how to replace in
Python:

For database-intensive webpages, I like to cache the HTML-output on the
fly in the filesystem and put out the file later whenever the same URL is
requested again, for example:
The problem with caching: When is
the data outdate?


Currently I just use the file creation date. I set it for example 2 weeks
into the future and whenever the creation date is in the past it is
assumend out of date.
You could use this approach:
Run a cron-job every hour which does the complicated
query which needs long to compute. Dump
the result into a file (Look for "pickle"
in the module index of the docs).


That wouldn't work, in fact it would make matters worse.

First of all, I couldn't have different times for caches to get out of date,
then, more importantly, I'd have to run it for every possible combination
at once, for example for script.php?a=1& b=2&c=3, I'd have to do all
combinations for a, b and c which could lead to thousands, sometimes
millions of combinations.
Also, there is no way to know which values of a, b and c are even possible,
so I wouldn't even know what to generate.
--
Harte Arbeit zahlt sich später mal aus. Faulheit sofort!

Jul 18 '05 #11
Ville Vainio wrote:
>> "rob" == Robert Ferber <ro*@nospam.net > writes:


rob> Hi, I'm a PHP-programmer who evaluates Python for a new
rob> project. I really like a lot of concepts of Python,
rob> especially the shell, but there is one great feature of PHP
rob> which I don't know how to replace in Python:

rob> <html>
rob> <? echo random_banner() ; ?>
rob> important database result that took 20 minutes to generate
rob> </html>

Check out the new mod_python, it offers exactly the functionality you
need. Some discussion is here:

http://www.onlamp.com/pub/a/python/2...ver_pages.html


This looks very promising, thanks a lot.
--
"Statistics are like bikinis. What they reveal is suggestive,
but what they conceal is vital" - Aaron Levenstein

Jul 18 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
5699
by: nospam | last post by:
Reasons for a 3-tier achitecture for the WEB? (NOTE: I said, WEB, NOT WINDOWS. DON'T shoot your mouth off if you don't understand the difference.) I hear only one reason and that's to switch a database from SQL Server to Oracle or DB2 or vice versa... and that's it.... And a lot of these enterprises don't need it as they already know what database they are going to use and they don't plan on switching in and out database in the first...
3
5223
by: Tony Sutton | last post by:
I have this following code in my html file: <object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab# version=7,0,0,0" width="320" height="320"> <param name="src" value="file.dcr" /> <embed src="file.dcr" pluginspage="http://www.macromedia.com/go/getflashplayer" width="320" height="320"> </embed>
9
6460
by: MTriggs886 | last post by:
There isn't a command that exists that can serve as an alternative to EMBED in HTML 4.01 Transitional coding, is there? I've historically used this command to play MIDI files in the background of my webpages, and I'm finding out now it's kind of obsolete, even though most browsers still accept it. Thanks, Michael Triggs
761
28986
by: Neo-LISPer | last post by:
Hey Recently, I researched using C++ for game programming and here is what I found: C++ game developers spend a lot of their time debugging corrupted memory. Few, if any, compilers offer completely safe modes. Unsurprisingly, there is a very high failure rate among projects using C++ for modern game development.
2
1868
by: Wezzy | last post by:
Hi, is there a tool that automatically expose an object to python? i have an instance of a C++ (or ObjC) object and i want to pass it to the embed interpreter that runs inside my program. Python code have to call c++ method and register some callback. I know that swig helps when python creates c++ instance but i've the instance and i want to use it with python. Thanks
1
3151
by: babylon | last post by:
if I have a Win32 DLL - X.DLL can I embed it to a .Net Application and invoke it's exported functions? normally i have to put the X.DLL in the file system and use DllImport to import/invoke the function I just wanna combine everything into a single .exe thank you
29
2914
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
42
2816
by: =?Utf-8?B?UGxheWE=?= | last post by:
I have an if statement that isn't working correctly and I was wondering how I check for a blank string. My Code Example if me.fieldname(arrayIndex) = "" then ----- end if When I do this and there is no characters in the variable it does not enter my IF statement like I would think it should. How do I properly check for a
2
1980
by: hardieca | last post by:
Hi, I'd like to know if anyone knows of any resources detailing the best practices of validating rules in the business tier and providing helpful error messages to users in the UI tier. All the information I have come across seems to revolve around using validation controls on the webpages themselves, which is not always feasible. Regards,
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10121
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.