|
|
18 Jan 2009 12:21:04 pm |
Let PHP running in background while browser think complete |
|
|
I need a PHP to be able to flush out the output and close the connection to the browser while the rest of the PHP can still be running.
I find them here: http://php.mirror.camelnetwork.com/manual/en/features.connection-handling.php
Code : Closing the users browser connection whilst keeping your php script running has been an issue since 4.1, when the behaviour of register_shutdown_function() was modified so that it would not automatically close the users connection.
sts at mail dot xubion dot hu
Posted the original solution:
<?php
header("Connection: close");
ob_start();
phpinfo();
$size=ob_get_length();
header("Content-Length: $size");
ob_end_flush();
flush();
sleep(13);
error_log("do something in the background");
?>
Which works fine until you substitute phpinfo() for
echo ('text I want user to see'); in which case the headers are never sent!
The solution is to explicitly turn off output buffering and clear the buffer prior to sending your header information.
example:
<?php
ob_end_clean();
header("Connection: close");
ignore_user_abort(); // optional
ob_start();
echo ('Text the user will see');
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush(); // Strange behaviour, will not work
flush(); // Unless both are called !
// Do processing here
sleep(30);
echo('Text user will never see');
?>
Just spent 3 hours trying to figure this one out, hope it helps someone  |
|
| |
Category : WEB programming
| By : Eric Shan | Comments [0] | Trackbacks [0] |
|
|
|
04 Jan 2009 10:02:02 am |
Proxy Server works in China |
|
|
http://proxypy.appspot.com/ |
|
| |
Category : WEB programming
| By : Eric Shan | Comments [0] | Trackbacks [0] |
|
|
|
04 Jan 2009 10:01:08 am |
Calculate php execution time |
|
|
The below php code can calculate how much time your PHP code costs.
Code : <!-- put this at the top of the page -->
<?php
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
?>
<!-- put other code and html in here -->
<!-- put this code at the bottom of the page -->
<?php
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo "This page was created in ".$totaltime." seconds";
> |
|
| |
Category : WEB programming
| By : Eric Shan | Comments [0] | Trackbacks [0] |
|
|
|
28 Dec 2008 11:57:11 am |
Zend remote debug setup in MAC leopard |
|
|
As Zend said to enable the remote debug, on the WEB server install the ZendDebugger.so, that is,
Zend Debugger installation instructions
---------------------------------------
1. Locate ZendDebugger.so or ZendDebugger.dll file that is compiled for the
correct version of PHP (4.3.x, 4.4.x, 5.0.x, 5.1.x, 5.2.x) in the
appropriate directory.
2. Add the following line to the php.ini file:
Linux and Mac OS X: zend_extension=/full/path/to/ZendDebugger.so
Windows: zend_extension_ts=/full/path/to/ZendDebugger.dll
Windows non-tread safe: zend_extension=/full/path/to/ZendDebugger.dll
(*) the windows non-thread safe is used only with Zend Core 2.0
3. Add the following lines to the php.ini file:
zend_debugger.allow_hosts=<ip_addresses>
zend_debugger.expose_remotely=always
4. Place dummy.php file in the document root directory.
5. Restart web server
But I got error when PHP is loaded from Apache, the error log recorded in /var/log/apache2/error_log shows,
Failed loading /usr/libexec/apache2/ZendDebugger.so: (null)
I test put the ZendDebugger.so both on /usr/lib/php/extensions, but still the same error.
The ip_address I put is 127.0.0.1/32.
Finally I find the answer here:
http://www.zend.com/forums/index.php?t=msg&th=5116&start=0&S=389fa3429c387381829cc761ca099b06
Stop Apache, then manually start apache with the command of,
sudo arch -i386 /usr/sbin/httpd
Although in the preference, can not see the apache is running, but actually it is running and Zend connect to debug without any problem. |
|
| |
Category : WEB programming
| By : Eric Shan | Comments [0] | Trackbacks [0] |
|
|
|
27 Dec 2008 12:13:33 pm |
Install Apache, PHP, mysql, phpmyadmin, Zend Studio on MAC |
|
|
Install Apache, PHP, mysql, phpmyadmin, Zend Studio on MAC leopard.
-Actually MAC intel has apache and PHP already built in in the system, so to
install Apache, PHP on MAC, just means enable it.
1. Enable Apache and PHP: go to System Preferences->Internet & Network-> Sharing->Web Sharing, click the it to enable it, this enable the Apache.
2. To install PHP on MAC, edit the file of /etc/apache2/httpd.conf, backup it before
modify it. Then remove the # on the sentence of
# LoadModule php5_module libexec/apache2/libphp5.so
After that go back to step one, shutdown Apache and restart it to make php start.
To test php is working, simply create a new php program by typing a program like below,
<?php phpinfo(); ?>
Then save this test.php at the folder under your user ID home directory's 'sites' folder. Then open Safari to navigate to the address of
http://localhost/~yourusername/test.php
so from now on the http://localhost/~yourusername, is mapped to your home directory's sites folder.
- To install mysql.
Download the mysql package mysql-5.0.67-osx10.5-x86.dmg, run the two installation package, then the double click the mysql.prefpane, this will install the Mysql icon in the system preferences, so you can start or stop Mysql server from there.
Try /usr/local/mysql/bin/mysql, this can execute sql sentence after on.
- To install phpmyadmin.
Download the package, phpMyAdmin-3.1.1-english.zip. unzip it into the subfolder of your 'sites' folder, then edit the file of config.sample.inc.php change the sentence of,
$cfg['Servers'][$i]['host'] = 'localhost';
to
$cfg['Servers'][$i]['host'] = '127.0.0.1';
after that use your safari to browse the address of http://127.0.0.1/~yourusername/yourphpadminfolder/, you should be able to see the login screen.
You need to create a user to make login from safari works, to do it run mysql, sudo /usr/local/mysql/bin/mysql, in mysql,
> CREATE USER admin@localhost IDENTIFIED BY 'createapassword' ;
>grant all privilleges on *.* to admin@localhost;
after that use your admin user with your new created password to log on from the Safari. Start using phpmyadmin.
-Install Zend Studio on MAC, download http://downloads.zend.com/studio/5.5.0/ZendStudio-5_5_0-Mac_OS_X.zip
Then upzip, and run the installer. |
|
| |
Category : Unix&Linux
| By : Eric Shan | Comments [0] | Trackbacks [0] |
|
|
|
14 Dec 2008 12:30:18 pm |
How google convertion tracking know if you are from adwords |
|
|
In 'google convertion tracking', I was wondering how google ensure this page is lead by google adwords and not by anything else. I think it was because a cookie was set when user click the adwords, and after that when this user visit the convertion tracking landing page, the information will be checked before google recorded it as a successful convertion. If google did not find the correct information in the cookie, it will not caculate as a successful convertion.
Who can prove it. |
|
| |
Category : About
| By : Eric Shan | Comments [0] | Trackbacks [0] |
|
|
|
21 Nov 2008 02:59:13 am |
Fix MyBloggie 2.1.6 |
|
|
In MyBloggie 2.1.6, it has a problem that when user click the Next page in the right end corner of the Homepage, the "Next" page did not show anything.
Checked the source code, looks like the index.php plus the parameter of "viewlist" is no longer exist in the handle list, so I test add a new "view" parameter, and let it do remove the parameter of "mode", this will make the index page think it was just has no Mode set.
What I did the change is,
1. In blog.php, change as below:
Code :
//$pagination = pagelink("viewlist", $pageno, $bloglimit, $numrow);
$pagination = pagelink("view",$pageno, $bloglimit, $numrow); // change to this
2. In index.php, change as below:
Code :
if ($right_menu){
if (isset($mode)) {
switch ($mode) {
case "viewid":
include 'view.php';
$search = false ;
break;
case "viewdate" :
include 'viewmode.php';
break;
case "viewmonth":
include 'viewmode.php';
break;
case "delcom":
include 'delcomment.php';
$search = false ;
break;
case "editcom":
include 'view.php';
$search = false ;
break;
case "viewcat":
include 'viewmode.php';
break;
case "search":
include 'search.php';
break;
case "viewuser":
include 'viewuser.php';
break;
case "view": //add this
unset($mode); //add this
break; // add this
default: include($mybloggie_root_path.'blog.php'); break;
}
}
......
if ($right_menu){
if (isset($mode)) {
switch ($mode) {
case "viewid":
include 'view.php';
$search = false ;
break;
case "viewdate" :
include 'viewmode.php';
break;
case "viewmonth":
include 'viewmode.php';
break;
case "delcom":
include 'delcomment.php';
$search = false ;
break;
case "editcom":
include 'view.php';
$search = false ;
break;
case "viewcat":
include 'viewmode.php';
break;
case "search":
include 'search.php';
break;
case "viewuser":
include 'viewuser.php';
break;
case "view": //add this
unset($mode); // add this
break; //add this
}
|
|
| |
Category : WEB programming
| By : Eric Shan | Comments [0] | Trackbacks [0] |
|
|
|
20 Nov 2008 07:02:17 am |
PHP函数前加@符号 |
|
|
函数前面可以加@, 用来防止向页面输出出错信息. |
|
| |
Category : WEB programming
| By : Eric Shan | Comments [0] | Trackbacks [0] |
|
|
|
15 Nov 2008 01:15:41 pm |
MAC Cocoa's Messagebox is NSAlert |
|
|
NSAlert can be use as MessageBox in MS Windows. |
|
| |
Category : Unix&Linux
| By : Eric Shan | Comments [0] | Trackbacks [0] |
|
|
|
25 Oct 2008 08:20:14 am |
MAC: create control or Window without NIB |
|
|
Just see a way to create button by code. Very interested in create Mac application purely by code and without anything from IB.
http://www.cocoadev.com/index.pl?NSButton
For Window and how an application load an window without an NIB, see this one,
http://objectmix.com/c/177994-how-create-windows-without-nib.html
Code :
int main(int argc, char *argv[])
{
NSWindow *mainwin;
MainView *mainview;
NSRect scr_frame;
unsigned int style_mask;
NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
scr_frame=[[NSScreen mainScreen] visibleFrame];
style_mask=NSClosableWindowMask|NSMiniaturizableWi ndowMask|
NSResizableWindowMask|NSTitledWindowMask;
#ifdef GNUSTEP
scr_frame=[NSWindow frameRectForScreenRect:scr_frame styleMask:style_mask];
#endif
scr_frame=[NSWindow contentRectForFrameRect:scr_frame
styleMask:style_mask];
mainwin=[[NSWindow alloc]
initWithContentRect:scr_frame
styleMask:style_mask
backing:NSBackingStoreBuffered
defer:NO];
[mainwin makeKeyAndOrderFront:nil];
[mainwin setTitle:@"Visible screen window"];
mainview=[[MainView alloc] initWithFrame:scr_frame];
[mainwin setContentView:mainview];
[mainwin setReleasedWhenClosed:YES];
[pool release];
[NSApp run];
return 0;
}
|
|
| |
Category : IPhone
| By : Eric Shan | Comments [0] | Trackbacks [0] |
|
|
|
Prev 1 2 3 4 5 6 7 Next |
|