PHP - Server Segfault's When Trying To Pdo::rollback() ...
Hi folks, I'll try my best to explain my problem... hopefully someone can shed some light on this... Essentially, I've written a "database wrapper" to handle any DB requests (selects, inserts, etc). It's using PDO... At some point in my dbwrapper, I create a wrapperStatement object, passing along by reference, the PDO connection. After creating this wrapperStatement object, I call a function within it that'll do multiple inserts....
On my NAS, this multiInserts() function seems to be cause a 500 http server error. When I tried running the same script, directly on the server's command line with php-cgi, I get a Segmentation Fault.
HOWEVER, I've installed PHP and Lighttpd on my working PC, and the code in multiInserts() just works ! class dbwrapper { ... $con = &$this->getConnection(); $dbwrapperStmnt = new wrapperStatement($con) $dbwrapperStmnt->multiInserts(); ... } class wrapperStatement { private $_conn; public function __construct(&$conn){ $this->_conn = &$conn; } public function multiInserts(){ // init data $data = array ( array ( "jdoe1", "jdoe1@email.ca", "abc1"), array ( "jdoe2", "jdoe2@email.ca", "abc2"), array ( "jdoe3", "jdoe3@email.ca", "abc3"), array ( "jdoe4", "jdoe4@email.ca", "abc4"), array ( "jdoe5", "jdoe5@email.ca", "abc5"), ); // init variables $username = null; $email = null; $passwd = null; $sql = "INSERT INTO users (USERNAME, EMAIL, PASSWD) VALUES (:username, :email, :passwd)"; try { $con = new PDO("mysql:dbname=somedb;host=somehost;port=3306", "user", "passwd"); $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //$con = $this->_conn; $stmt = $con->prepare($sql); $stmt->bindParam(':username', $username, PDO::PARAM_STR); $stmt->bindParam(':email', $email, PDO::PARAM_STR); $stmt->bindParam(':passwd', $passwd, PDO::PARAM_STR); } catch ( PDOException $ex ) { die($ex->getMessage()); } $errorList = array (); $totalRows = count($data); for ( $row = 0; $row < $totalRows; $row ++ ) { $username = $data[$row][0]; $email = $data[$row][1]; $passwd = $data[$row][2]; try { $con->beginTransaction(); $stmt->execute(); $con->commit(); } catch ( PDOException $ex ) { // HERE!!! // IF USING $this->_conn AS CONNECTION, SEGFAULT IS PRODUCED ON ROLLBACK! if ( $con->inTransaction() ) $con->rollBack(); // just push the error to an array of failed transactions array_push($errorList, array ( $row, $ex->errorInfo[1], $ex->getMessage() )); } } if ( $errorList ) { // print the errors foreach ( $errorList as $error ) { echo "Row #:" . $error[0] . "<br>"; echo "Code :" . $error[1] . "<br>"; echo "Mesg :" . $error[2] . "<br><br>"; } } } }
What I've also found, if running on my NAS, is that if instead of using $this->_conn as my connection object (which I really should!), I create a NEW PDO object and use that one instead, it works, no segfaults!!
So, the #2 tells me it's the same object! (or am I mistaking?). It should be good. I still tried passing the $con object to my statement constructor as a 'copied' value instead of a reference, and problem remains.. changes nothing! $pdoAttribs = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_AUTOCOMMIT => false, PDO::ATTR_PERSISTENT => true ];
Here's a link to my phpinfo() : http://corbeauperdu.ddns.net/phpinfo.php # Special Configuration file for the DNS-325 # web servers are declared as virtual hosts # include, relative to dirname of main config file include "/etc/lighttpd/lighttpd.conf" # adding extra modules server.modules += ( "mod_redirect" ) server.modules += ( "mod_compress" ) # PRoy: enable compression module server.modules += ( "mod_expire" ) # PRoy: used to set expiry time for cache on clients # add support for new virtual host $HTTP["host"] =~ "(^|\.)myhost.ddns.net$" { server.document-root = "/srv/WWW/html" server.errorlog = "/srv/WWW/logs/error.log" server.error-handler-404 = "/blog/index.php" accesslog.filename = "/srv/WWW/logs/access.log" # files to check for if / is requested index-file.names = ( "index.php", "index.html", "index.htm" ) ########### # PRoy: compress content to DISK as to save CPU-cycles when requesting these file types (otherwise, CPU will compress it all everytime!) compress.allowed-encodings = ("gzip", "deflate") compress.filetype = ("text/plain", "text/html", "text/javascript", "text/css", "text/xml" ) compress.cache-dir = "/srv/WWW/tmp/wwwcache" ########### # PRoy: setup CACHING on clients # make clients think their content is already up-to-date # mod_expire will actually send a Cache-Control / Expires HTTP header on each item it's called upon (css, jpg, or etc) or called URL path # # Cache based on suffix $HTTP["url"] =~ "\.(jpg|gif|png|css|js|eot|svg|ttf|woff|woff2)$" { expire.url = ( "" => "access plus 13 months" ) } # Cache based on path expire.url += ( "/calchom/css/" => "access plus 13 months", "/blog/videos/" => "access plus 13 months", ) # Anything else not caught by mod_expires will be cached on client with these directives setenv.add-response-header += ( # cache for 1 month #"Cache-Control" => "public, max-age=2592000, must-revalidate, proxy-revalidate" # no cache at all! "Cache-Control" => "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0, post-check=0, pre-check=0" ) ########### cgi.assign = (".cgi" => "") static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".cgi" ) flv-streaming.extensions = ( ".flv" ) ########## # PHP Server configuration php-cgi vs php-fpm) # PHP-CGI (2020-02-02 : works good!) # Normally, PHP-FPM should be faster, but not on NAS (?) fastcgi.server = ( ".php" => ("localhost" => ("bin-path" => "/ffp/bin/php-cgi", "socket" => "/tmp/php-cgi.socket", "bin-environment" => ( "PHP_FCGI_CHILDREN" => "0" ), "max-procs" => "1") ) ) ########### server.upload-dirs=( "/srv/WWW/tmp/wwwuploads" ) server.max-request-size = 4194303 server.network-backend="writev" }
Million thanks!! Similar TutorialsI am new to MySQLI and tried to test the rollback functionality. I created a simple database called mysqli and one table called test with and id and name field. my PHP is as follows: Code: [Select] $mysqli = new mysqli('localhost',name,password,'mysqli'); $mysqli->autocommit(FALSE); $result = $mysqli->query("INSERT INTO test (name) VALUES('bla')"); $mysqli->commit(); $mysqli->rollback(); After hitting the page, it does the insert, but does not roll back the transaction. So it ends up being inserted into the DB. Why is the rollback not working? In my one php registration form i have generated one code automatically and if multiple users registering on form then each registration should be on different code but right now its not working. Right now if only two users using same form, still it is registering same code for two records. Please tell me how to make it perfect for multiple users??? Following i am sharing my core php code, Please tell me whether it is correct or wrong and tell me the changes also:
<?php
// Insert
// Insert Query
$DB_Error = "Database Error => ".mysqli_error($dbCon); ?>
<script type="text/javascript">
I have a PHP web system that store in a windows server. In the system, there is a function for user to upload files to another server (Shared server in Unix). When i try to upload a file, it gives warning: Warning: move_uploaded_file(\\unixserver/sharedfolder/upload/test.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\wamp\www\upload\index.php on line 40 For your information, my username has been assigned in xxx's group that has access to read and write on that folder. Besides, i'm able to open,create and delete files on that folder's server manually (samba). The safe mode setting is off. Does anybody has any idea why this thing happen? I'm trying to make a simple website where people register to my website. When the user doesn't fill anything inside the boxes they get a message "Please fill all required fields" on the register.php page On my local host require_once works good. It shows up.
But when i upload the files to my sever the require_once does not show up on the register.php It just refreshes and i dont get the message "Please fill all required fields"
This is the code that works in local host but not in a live server <?php require_once 'messages.php'; ?>
Here is my full code
Register page: <html> <?php require_once 'messages.php'; ?> <br><br> <form action="register-clicked.php" method="POST"> Username:<br> <input type="text" name="usernamebox" placeholder="Enter Username Here"> <br><br> Email:<br> <input type="text" name="emailbox" placeholder="Enter email here"> <br><br> Password:<br> <input type="password" name="passwordbox" placeholder="Enter password here"> <br><br> Confirm Password:<br> <input type="password" name="passwordconfirmbox" placeholder="Re-enter password here"> <br><br> <input type="submit" name="submitbox" value="Press to submit"> <br><br> </form> </html>
Register clicked <?php session_start(); $data = $_POST; if( empty($data['usernamebox']) || empty($data['emailbox']) || empty($data['passwordbox']) || empty($data['passwordconfirmbox'])) { $_SESSION['messages'][] = 'Please fill all required fields'; header('Location: register.php'); exit; } if ($data['passwordbox'] !== $data['passwordconfirmbox']) { $_SESSION['messages'][] = 'Passwords do not match'; header('Location: register.php'); exit; } $dsn = 'mysql:dbname=mydatabase;host=localhost'; $dbUser='myuser'; $dbPassword= 'password'; try{ $connection = new PDO($dsn, $dbUser, $dbPassword); } catch (PDOException $exception){ $_SESSION['messages'][] = 'Connection failed: ' . $exception->getMessage(); header('Location: register.php'); exit; }
messages.php <?php session_start(); if (empty($_SESSION['messages'])){ return; } $messages = $_SESSION['messages']; unset($_SESSION['messages']); ?> <ul> <?php foreach ($messages as $message): ?> <li><?php echo $message; ?></li> <?php endforeach; ?> </ul> Edited Wednesday at 12:49 AM by bee65 Hi, I am not a PHP programmer. I took on a new client with a simple PHP site, without any databases. The site is up and running on the web. I would like to get it running on my local machine for further development. I have latest version of WAMP installed, running Apache version 2.2.11 and PHP version 5.3.0 I created a directory in the WAMP "www" project directory and it shows up there like it's supposed to when I browse to "localhost" Problem: The home page of website displays text but no, images, styles, footer, header, nav links, etc. Here is the code for the home page: <? define("NAV","home"); require_once('local/local.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>TITLE</title> <meta name="keywords" content=""> <meta name="Description" content=""> <? include("common/dochead.php"); ?> </head> <body onLoad="<? include('common/preloads.php'); ?>"> <!-- ============================ main ============================= --> <div id="main-frame"><div id="main" class="noCollapse"> <? include("common/sign.php"); ?> <div id="right-frame"> <? include("common/navigation.php"); ?> <div id="content-frame"> <div id="content"> <h1>Welcome</h1> <p>This is the content area. This is the content area. This is the content area. </p> </div><!-- end content --> </div><!-- end content-frame --> </div><!-- end right-frame --> <div class="clearFloats"></div> </div><!-- end main --></div><!-- end main-frame --> <? include("common/footer.php"); ?> </body> </html> Any help would be greatly appreciated. I have spent many hours on this. Regards Hi folks, I'm curious if I can for example, save a file from my server and it will save to all other servers - obviously if they accepted the connection first. It's for a software I developed and is almost complete and know there will be frequent updates to it. Instead of users downloading upates, I want the update files from my server to somehow synchronize to their server automatically? Anything called this?? Thanks for info. This isn't exactly an application design question, but rather a system design one.
I am about to install an Inventory Control System inside this store I work in.
The store itself also owns a Linode VPS running Centos 6.4 which hosts our website.
This new Inventory System will come built in with a Microsoft SQL Server, and supposedly it is a SQL Anywhere database, but I'm not too sure what that means.
I need to make this database publicly accessible, but only via the Linode VPS. Surely, setting restrictions is easy enough to address that issue. That isn't my question.
My first idea is to put this server into the DMZ, easy. But it doesn't exactly sound safe. So my next idea was to put a middleman server in the DMZ, this way the Linode can send queries to that middleman server and it will send that data to the SQL Server and back. This is very vaguely described I know, but I don't want to get too much into details, but rather, understand how I can create that middleman server, and what could Install onto it that would allow me to securely process queries?
My first thought was to install a webservice, that accepts an XML/JSON request and returns an XML/JSON response.
Then, I realized directly afterwards that I don't have any experience setting up a webservice like that.
What kind of options are there out there? Ultimately, my question is, should I just put the Server in the DMZ or should I create the middleman, and if so, can someone point me in the right direction as to getting a webservice set up? Edited by Zane, 15 July 2014 - 11:28 PM. Following a tutorial on udemy, i tried to learn the very basics of mvc structure. I built the same project on my local server and it worked without giving me any error. but when i tried it on live server. its not working as it should. not showing any error. I tried to figure out the problem and found that for every page loading, it stops at the same line in my main.php file. <?php require($view); ?> starting from the above line. it stops. i came here to share my problem but i am unable to upload my files here. if there is a way to upload and share my files, please guide. zip file size of the whole project is 31.6 kb Hey. I am wanting to move a couple of files from my current server to another. If i am uploading the file this is fine but if it is already on the server then im not sure how to move it. When uploading I can just use ftp_put($conn_id, $destination_file, $myFile, FTP_BINARY); What i need to do is figure out how to get a hold of the file and store it in $myFile then this would work fine. Is this possible? Cheers (This might be the wrong forum; it might be server-side configuration, but alas it is the code that *calls* fwrite, so I'll start here.) I have written a script, and one thing it does is generate a file to disk using fwrite. No big deal. Here's what interests me: On most servers, the file is written successfully when the folder's permissions are 755 with recursive permissions. On some servers, 755 fails. Only 777 works. How could this be? Are permissions=permissions=permissions? Why will 755 work on one machine but not another? I'm just a logic guy; I know very little of server-side configuration and/or why there would be a difference here. Just trying to learn. What I'm trying to do is copy all files from one server to another folder on another server. Here is what I have have so far.. <?PHP //connection settings $ftp_server = "server"; $ftp_user_name = "user"; $ftp_user_pass = "pass"; $dir = "/var/test/"; $destination_file = "/test/"; // set up basic connection $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // check connection if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!"; echo "Attempted to connect to $ftp_server for user $ftp_user_name"; exit; } else { echo "Connected to $ftp_server, for user $ftp_user_name"; } if (ftp_chdir($conn_id, $dir)) { echo " <br/>Current directory is now: " . ftp_pwd($conn_id) . "\n<p/>"; } else { echo "Couldn't change directory\n<p/>"; } $buff = ftp_rawlist($conn_id, $dir); foreach($buff as $files) { echo $files. "<br/>"; if (ftp_get($conn_id, $destination_file."test.file", $dir."test.txt", FTP_BINARY)) { echo "<br/>Successfully written to $destination_file\n"; } else { echo "There was a problem\n"; } ?> That doesn't work. Any ideas? Thanks, Sean I have two servers: WebServer and FaxServer. WebServer needs to send a fax. Is my approach shown below fairly secure? Before sending a fax, ServerWeb needs to store a record in a table representing the message, and I am using a pseudo random value for the PK which is generated as 2147483648+mt_rand(-2147483647,2147483647). WebServer then generates a hash equal to hash('sha256',$pk.'secretCodeWhichOnlyWebServerAndFaxServerKnow'). WebServer then sends curl request to FaxServer using POST which includes $pk, the hash, the fax number, some text to include in the fax, and an optional array of document to include (array(array('id'=>321,'name')=>'fileName.pdf')). FaxServer verifies that the hash is correct given $pk, that the minimum information has been received, and that the fax number is a valid phone number, and quickly responds to WebServer by echoing 0 or 1 so the code in the WebServer could continue and inform the user. If all looks okay, a new instance of PHP is started. if(missingInformation) {echo(0);} else { session_start(); $_SESSION['_xfr']=$_POST; exec('/usr/bin/php -q /path/to/send_fax.php '.session_id().' >/dev/null &'); echo(1); }New instance of PHP send_fax.php then does the following: session_id($argv[1]);//Set by parent session_start(); $data=$_SESSION['_xfr']; $doc_list=null; foreach ($data['documents'] AS $doc) { if(ctype_alnum($doc['id'])) { $file='/some/tmp/directory/'.$doc['id']; if(!file_exists($file)) { $url='http://machine.WebServer.com/index.php?task=displayDocument&id='.$doc['id'].'&x='.hash('sha256','displayDocument'.$doc['id'].'secretCodeWhichOnlyWebServerAndFaxServerKnow'); $cmd='wget -O '.$file.' '.escapeshellarg($url); exec($cmd); } $doc_list.=' '.$file; } exit('invalid document'); } //Send the fax... //Send another CURL request to the WebServer similar to the wget giving the fax status. exit;When WebServer receives the wget request for a document, it confirms the hash and sends the document to the FaxServer using X-Sendfile. When WebServer receives the CURL request regarding status, it updates the database for the applicable message. Seem reasonably secure? I wish to create validation rules once which are used both on the client and on the server.
For instance, I will start off with the following PHP object:
stdClass Object ( [rules] => stdClass Object ( [email] => stdClass Object ( [required] => 1 [email] => 1 [remote] => stdClass Object ( [url] => check-email.php [type] => post [data] => stdClass Object ( [username] => function() {return $( '#username' ).val();} ) ) ) ) [messages] => stdClass Object ( [email] => stdClass Object ( [required] => an email is required ) ) )When the edit page is downloaded to the client, I will include this object in some format suitable to the client. The client will then use the jQuery Validation plugin (http://jqueryvalidation.org/) along with the validation object, and client side validate the page. When the form passes client side validation and is uploaded, PHP will use the same validation object to serverside validate the form (I have this part working as desired). My question is how should I pass this data to the client? Originally, I would just use PHP to write some JavaScript. exit('var myObj='.json_encode($myObj));Note that when I json_encode the object, the value of $myObj->rules->email->remote->data->username is a string with quotes around it, however, I can easily use PHP to strip these tags before sending it to the client. As Jacques1 pointed out in http://forums.phpfre...ascript-client/, I should never ever use PHP to generate JavaScript, and should use AJAX to download the JSON directly. I tried doing the later, but found that a callback function could not be included in the JSON. Please advise on the best way to accomplish this. Thank you I just did a huge import from an app I have been working on. No issues except for this. I uploaded & imported all files & databases from my wampserver (localhost, local server) to my main online server. Before I continue with the problem, I have to give you info on how the files work. I am using a "controller" to view the files. Meaning, from index.php, I call all the files. For example, instead of mysite.com/register.php, its mysite.com/index.php?page=register. The index defines the doctype & html tags etc. The other files that are called through index.php are just pure php code, it does not contain the head & body tags etc. So, the issue is , when the surfer submits a form, i need to set a cookie. this cookie is VERY important. I cannot get it to work. I am getting the header warnings after submit Of course, this is to be expected. But I tried it on my local server, & it worked. I am not very familiar with cookies, this is a side of PHP i never really even touched. I know almost everything but that. So the php code is before the html code on the page, so I figured it was worth a shot. Im guessing the problem here is, since the code being outputted as index.php code + the form page code. So the cookie is being set after the html tags. How can I fix this? I need it to work thru the controller. I cannot just make it a single file, all files on the site needs to be thru this controller, otherwise it will mess everything up. Ino I could just add the code from index.php plus the form page code & just run the php code before all of the html tags, but like I said it has to be called thru index.php. I appreciate your replies, & I hope you guys dont think im an idiot & can understand my question, im terrible with words! Hello, I want to ask you, how to code the next problem I want to transfer some coins from site A to site B, I have access to both sites. My question is, how can I update table on site B, when I send request for updating on site A. Basicly, I need to transfer value from site A, and site B should receive this value, and update table. How can I do it, what do I need? Hi, I would like to transfer some jpg image files from FTP server to my local server and I would like this to be done in a PHP script but I cannot figure out a way to do this without saving in my local harddrive. If anyone have any ideas and share this with us that would be very much appreciated!!! Thank you. Kind regards, Jae Hi I am on working on a communication system, on my computer I use xampp. On my computer I have created this one app, working with mysqli as well. On my system everything works perfectly...nothing goes wrong, all queries execute correctly. But when I upload this app...Its as the queries does not execute. When I use mysqli_fetch_array() function gives error and say that the first parameter is an boolean. The connection is correct and everything. Is there a chance that the fault is on the server's side and that it needs to be restarted? What can you recommend I should do? Thanks What would be the best way to return: One image (let's say, green.png) if the specified website is up Second image (let's say, red.png) if the specified website is down Third image (let's say, orange.png) if the website is slow. Would the best option be to use file_get_contents()? Or a exec() Hi all, I have an ajax comment system that is meant to be quite simple! This works fine on localhost, but when on my vps for some reason its throwing a 500 error. I have checked the logs but nothing is mentioned. I am wondering if anyone can throw some light on where to start? Chrome shows this: Request URL:http://www.buy2earn.co.uk/submit.php Request Method:POST Status Code:500 Internal Server Error Request Headers Accept:application/json, text/javascript, */* Content-Type:application/x-www-form-urlencoded Origin:http://www.buy2earn.co.uk Referer:http://www.buy2earn.co.uk/viewm.php?m_id=1 User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7 X-Requested-With:XMLHttpRequest Form Data name:admin merchant:1 body:gjgjkgj Response Headers Connection:close Content-Length:0 Content-Type:text/html; charset=UTF-8 Date:Tue, 23 Nov 2010 19:48:22 GMT Server:Apache/2.2.3 (CentOS) X-Powered-By:PHP/5.2.13 submit.php exists at the location shown Hello, please can anyone advise a right solution on how to avoid my site acting strangely when one of my AD companies stops to function. I mean there are downtimes for AD servers as well, and i'm wondering what is the best solution? Can i load ads on my pages separately, so i mean lastly? They are all over my page so i guess i can't do it. Or is it better to ping ad server and wrap these ADS around PHP if functions, which ping these servers? If you have a solution , which is most effective, please tell me. |