|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-09-05 17:12 UTC] marcin dot wanat at gmail dot com
Description: ------------ PHP 5.2.4 (FCGI), APC from CVS loading module apc.so in php.ini cause each php process has own cache (as far as i can see by reloading apc.php). Is it possible on to share one cache between all processes ? APC conf: ./configure --enable-apc-spinlocks php.ini: extension=apc.so apc.enabled=1 apc.shm_segments=1 apc.shm_size=1024 apc.num_files_hint=10000 I found similar 'bug' reported with WIN32, but maybe it is possible on linux or freebsd ? PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 21:00:02 2025 UTC |
Rasmus, i looked at apc_mmap(). I try to remove "unlink" and "mkstemp" in apc_mmap.c in last section (regular files) to make one cache for all system. Now it looks like that: else { struct passwd *userinfo; char file_mask2[250]; //fd = mkstemp(file_mask); userinfo=getpwuid( geteuid()); sprintf(file_mask2,"%s-%s",file_mask,userinfo->pw_name); fd = open(file_mask2, O_CREAT|O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if(fd == -1) { apc_eprint("apc_mmap: mkstemp on %s failed:", file_mask); return (void *)-1; } if (ftruncate(fd, size) < 0) { close(fd); //unlink(file_mask); apc_eprint("apc_mmap: ftruncate failed:"); } shmaddr = (void *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NOSYNC, fd, 0); close(fd); //unlink(file_mask); } } if((long)shmaddr == -1) { apc_eprint("apc_mmap: mmap failed:"); } return shmaddr; } It is also add current user name to "file_mask". Files "file_mask.username" are created, but there is too much segmentation faults. So it not work. I try to switch to shm (--disable-mmap), and change apc_shm.c, adding one fixed key id and set permission flags to grant r/w access to all processes, also remove apc_shm_destroy call to make shared memory segment persistent between all fastcgi processes. int apc_shm_create(const char* pathname, int proj, size_t size) { int shmid; /* shared memory id */ int oflag; /* permissions on shm */ key_t key; /* shm key returned by ftok */ key = IPC_PRIVATE; #ifndef PHP_WIN32 /* no ftok yet for win32 */ if (pathname != NULL) { if ((key = ftok(pathname, proj+1)) < 0) { apc_eprint("apc_shm_create: ftok failed:"); } } #endif // oflag = IPC_CREAT | SHM_R | SHM_A; //old flag oflag = IPC_CREAT | 0666; key=11; //fixed key for test if ((shmid = shmget(key, size, oflag)) < 0) { apc_eprint("apc_shm_create: shmget(%d, %d, %d) failed: %s. It is possible that the chosen SHM segment size is higher than the operation system allows. Linux has usually a default limit of 32MB per segment.", key, size, oflag, strerror(errno)); } return shmid; } void* apc_shm_attach(int shmid) { void* shmaddr; /* the shared memory address */ if ((long)(shmaddr = shmat(shmid, 0, 0)) == -1) { apc_eprint("apc_shm_attach: shmat failed:"); } /* * We set the shmid for removal immediately after attaching to it. The * segment won't disappear until all processes have detached from it. */ // apc_shm_destroy(shmid); // REMOVED THIS return shmaddr; } But there is segmentation fault too. error_log: "Premature end of script headers: script.php". strace on php-cgi shown last call to "futex(". It will be very nice, if apc will have 2 options: 1. One fixed size cache for entry server, shared between all users and fcgi processes. Ideal for dedicated server, where hosted only trusted or own projects, and when different user/sites need to share the same data. 2. One cache for each user, shared between each fcgi processes under same user. Ideal for not trusted hosting. p.s. apc from cvs head, php 5.2.6.